EXIF and IPTC support and autorotate possible?

After taking a bit more of a look, and linking to another couple sites, I found a couple ideas for those of you who might want to try the imagerotate by EXIF feature. (Figured I'd start a new thread, because this is off-topic for the subalbums.)

Here's your imagerotate feature (possibly):

<?php
function imagerotate($src, $angle, $dummy) {
$width = imagesx($src);
$height = imagesy($src);

if ($angle == 90 || $angle == 270)
$dst = imagecreatetruecolor($height, $width);
else
$dst = imagecreatetruecolor($width, $height);

for ($y = 0 ; $y < $height ; $y++) {
for($x=0;$x<$width;$x++) {
switch ($angle) {
case 90:
imagecopy($dst, $src, $height-$y-1, $x, $x, $y, 1, 1);
break;
case 180:
imagecopy($dst, $src, $x, $y, $width-$x-1, $height-$y-1, 1, 1);
break;
case 270:
imagecopy($dst, $src, $y, $width-$x-1, $x, $y, 1, 1);
break;
default:
imagecopy($dst, $src, $x, $y, $x, $y, 1, 1);
}
}
}
imagedestroy($src);
return($dst);
}
?>

Looks like it could potentially plug right in to i.php.

Then, including an EXIF library, like:

http://www.ozhiker.com/electronics/pjmt/

Which would in turn give you your capabilities (i think) to autorotate. Now i'm not a super-PHP expert. I can read code, and somewhat follow it, but if someone else look at these suggestions, they might be viable for inclusion into the zenphoto libraries. The code snippet above was culled from another image gallery called NAIG (not another image gallery). I don't advocate "stealing" the code, but it should give enough ideas as how to write an efficient function to handle autorotating from EXIF. I just don't know how myself.

Thinkdreams.

Comments

  • I do have a question though. After reviewing the EXIF functions that Skwid and I put into the Zenphoto theme we built, what advantage does IPTC information offer vs. EXIF? EXIF seems to have quite a bit of information, where IPTC is specific to the image editing app you use to edit the metadata? I can see where the autorotate feature would be mighty useful.

    Is the assumption that this metadata can be used to manipulate pictures in zenphoto i.e. showing only pictures with ISO 400 or better, or sorting by date/time taken?

    Thinkdreams
  • I've added a patch for reading exif orientation to the latest development version. You can also rotate even if you don't have exif info on some of your pictures.

    The patch is here:
    http://www.zenphoto.org:8080/browse/ZEN-61

    I'll try to add this back to the 1.0.3 version sometime soon so that others can try it out.
  • trisweb Administrator
    I can take care of the backporting once I have time to look at it and integrate. :)

    Thanks! This looks good.
  • Sorry I just realized that the try catch block isn't necessary and isn't supported in php4 in the class.php file. If you could take that out it would be cool!
  • justin Member
    sorry if this has been posted elsewhere, but how do i apply this patch? Not sure what do after downloading it, thanks :)
  • icamp Member
    I'm with Justin. Are there any instructions for how to use this patch? I don't want to just drop it in my zenphoto directory without knowing what I'm doing.

    Thanks!
  • Dito... don't know what to do with the *.patch file ...
Sign In or Register to comment.