Jump to content

How do I reference the image path from a single image in a page?


Recommended Posts

Posted

I am getting my IPTC and EXIF data to show up great with this code for a static single image. If I can build a template and  get $filename to dynamically link to the path of a single image uploaded to a page, I can have a pretty simple gallery page that will display the image and the exported meta data. I have all of this data already in Aperture, so it would be great to use the IPTC data for keywords, titles and captions etc.  I tried $image->url, but it is not working. Any help would be appreciated.Thanks.

<?php
// Point to image file
  $filename = "http://localhost:8888/processwire2/site/templates/styles/images/image.jpg";

$IPTC_Caption = "";
$size = getimagesize($filename, $info);
if (isset($info["APP13"])) {
    if($iptc = iptcparse( $info["APP13"] ) ) {
        $IPTC_Caption = str_replace( "\000", "", $iptc["2#120"][0] );
        if(isset($iptc["1#090"]) && $iptc["1#090"][0] == "\x1B%G")
            $IPTC_Caption = utf8_decode($IPTC_Caption);
    }
}

   

  $exif = exif_read_data($filename, 0, true);

  
  echo "Title: " . $iptc["2#005"][0] . " <br />";
  echo "Caption: " . $iptc["2#120"][0] . " <br /><br />";
  echo "Shutter Speed: " . $exif["EXIF"]["ExposureTime"] . " <br />";
  echo "Aperture: " . $exif["COMPUTED"]["ApertureFNumber"] . " <br />";
  echo "ISO: " . $exif["EXIF"]["ISOSpeedRatings"] . " <br />";
  echo "Camera: " . $exif["IFD0"]["Model"] . " <br />";
  echo "Focal Length: " . $exif["EXIF"]["FocalLengthIn35mmFilm"] ."mm<br>";  
  echo "Copyright: " . $iptc["2#116"][0] . " <br />";

  ?>
Posted

It seems as if this could be adapted to work... it does not use $config->paths->root, but it pulls all of the urls in the echo href statement. I know that this works. I just don't want a for each, or do I?

<ul class='gallery'>
<?php
  
foreach($page->images as $img) {
$t = $img->size(150, 125);
echo "<li><a class='gallery' title='{$t->description}' rel='group' href='{$img->url}' ><img id='dropshadow' src='{$t->url}' alt= width='{$t->width}' height='{$t->height}' /></a></li>";

}

?>

</ul>

Posted
$filename = "http://localhost:8888/processwire2/site/templates/styles/images/image.jpg";

$IPTC_Caption = "";

$size = getimagesize($filename, $info);

Since you are using getimagesize() that function wants a disk path, not a URL. You'd want to use:

<?php
$img->filename; // returns full disk path

or if you have multiple images, you'd loop through them, or grab one of them and retrieve it's filename.

Posted

Thanks Ryan,

I got it to work in the loop, which is fine for one image, and great for more than one.

<ul class='gallery'>
<?php
  
foreach($page->images as $img) {
    $diskpath = $img->filename;
    $exif = exif_read_data($diskpath, 0, true);
    $size = getimagesize($diskpath, $info);
    $iptc = iptcparse($info['APP13']);
    $t = $img->size(200);

    echo "<li><a class='gallery' title='{$t->description}' rel='group' href='{$img->url}' ><img id='dropshadow' src='{$t->url}' alt= width='{$t->width}' height='{$t->height}' /></a></li>";
    echo "Title: " . $iptc["2#005"][0] . " <br />";
    echo "Caption: " . $iptc["2#120"][0] . " <br /><br />";
    echo "Shutter Speed: " . $exif["EXIF"]["ExposureTime"] . " <br />";
    echo "Aperture: " . $exif["COMPUTED"]["ApertureFNumber"] . " <br />";
    echo "ISO: " . $exif["EXIF"]["ISOSpeedRatings"] . " <br />";
    echo "Camera: " . $exif["IFD0"]["Model"] . " <br />";
    echo "Focal Length: " . $exif["EXIF"]["FocalLengthIn35mmFilm"] ."mm<br>";  
    echo "Photographer: " . $iptc["2#116"][0] . " <br />";
}

?>
</ul>

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...