Can we rotate images?

I'm sorry, but I've searched the forums here and haven't really found my answer...

I think the auto-rotating would be awesome, but I'm patient and can wait for that.

Zen Photo is almost perfect for my needs, except for my few photos that need rotating. Is there a place in the admin hiding a rotate feature? Is there a add on I can install that will just allow me to rotate an image 90 degrees either way?

All I want is a gallery where people don't need to tilt their heads to see a photo!

Comments

  • http://www.zenphoto.org/trac/ticket/111

    Since there are only a few images, why not rotate them with a photo editing program and then upload them?
  • Well, a few images scattered across dozens and dozens (more than a hundred) of folders - it's an archive of every single photograph I've taken over the last 6 years. I've already rotated many of them, but to sit and go through the folders to find them all would take forever - I guess I just want the ability to rotate a photo if I happen to notice that one is still oriented the wrong way.

    And I know the auto-rotate is coming, I was just hoping maybe someone had done an add-on or hack to give the ability to rotate a photo, perhaps from inside the gallery instead of in the admin.

    Thanks for your help!
  • Say how far along is this autorotate thing? I don't see it in the 1.1.6 trac and the above link is old indicating that imagemagick needs to be integrated beforehand and I don't see it in the trac either.

    So love to hear what is in the works so that I don't have to butcher the existing code to put something that sort of works....

    Oh what's the reasoning behind the imagemagick? Sorry if this has already been addressed, I only started coding in php 30 mins ago because full_image.php didn't have the function to resize the full image regardless of how big the image and compress it. But after reading on the functions, php does have a imagerotate function and I know you have some sort of exif function already. So why the need for imagemagick?
  • http://www.zenphoto.org/trac/search?q=rotation&wiki=on&changeset=on&ticket=on

    BTW, the reason full_image does not resize the image is because it is FULL IMAGE. It wouldn't be a full image if it was resized, would it?

    imagerotate is a feature of PHP 4.3 and greater. We require version 4.1 or greater, so we cannot use this routine.
  • Yep I know but that's a custom thing I wanted so I made it myself for the full image download.

    Ok understood with the imagerotate. Looks like from your link it's going to be pushed ahead to milestone 1.2. So not anytime soon.

    Guess I'll have to work on patching the current version. I'm going to use imagerotate along with the native exif support in PHP 4.3 since I'm already at least that level.

    Thought it was going to be easy but I'm two hours into it and still trying to figure out what is called from where. I've already patched functions-image.php so that the result cache files are rotated. Now I have to figure out where the function calls are for the width and height of these images so the img src width and height tags are so they don't squish my images.
  • OK I think this works. I'm a sloppy coder and this is my first time with PHP so don't shoot me! If anyone's interested they can explore it more. Again this is the autorotate function and it leaves the original files intact. It requires PHP 4.3 and the php exif support enabled (it came installed with my fedora core 6 so I really didn't have to do anything).

    There's two files modified. First function is the updateDimensions() in class-image.php. Not sure how many places it's called but this is where the width and height is called for the <img src> tag. If you don't do this you will have squishy images because it still thinks you have the landscape format. Second function is the cacheGalleryImage() in function-image.php. This is where the imagerotate function is used to rotate the images for the cache images.

    function updateDimensions() {
    /*
    * FIXME: Temporarily getting dimensions each time they're requested. Should be same as EXIF extraction (see TODO).
    * TODO: Update them if they change by looking at file modification time, which must be stored in the database.
    */
    if ($this->video) {
    $size = array('320','240');
    } else {
    $size = getimagesize($this->localpath);

    }

    $this->set('width', $size[0]);
    $this->set('height', $size[1]);

    $exif = exif_read_data($this->localpath,0,true);
    $ort = $exif['IFD0']['Orientation'];
    switch($ort)
    {
    case 1: // nothing
    break;

    case 2: // horizontal flip
    break;

    case 3: // 180 rotate left
    break;

    case 4: // vertical flip
    break;

    case 5: // vertical flip + 90 rotate right
    break;

    case 6: // 90 rotate right
    if($size[0]>$size[1]){
    $this->set('width', $size[1]);
    $this->set('height', $size[0]);
    }
    break;

    case 7: // horizontal flip + 90 rotate right
    break;

    case 8: // 90 rotate left
    if($size[0]>$size[1]){
    $this->set('width', $size[1]);
    $this->set('height', $size[0]);
    }
    break;
    }

    }

    function cacheGalleryImage($newfilename, $imgfile, $args, $allow_watermark=false, $force_cache=false) {
    @list($size, $width, $height, $cw, $ch, $cx, $cy, $quality, $thumb, $crop) = $args;
    // Set the config variables for convenience.
    $image_use_longest_side = getOption('image_use_longest_side');
    $upscale = getOption('image_allow_upscale');
    $sharpenthumbs = getOption('thumb_sharpen');

    $newfile = SERVERCACHE . $newfilename;
    // Check for GD
    if (!function_exists('imagecreatetruecolor'))
    imageError('The GD Library is not installed or not available.', 'err-nogd.gif');
    // Check for the source image.
    if (!file_exists($imgfile) || !is_readable($imgfile)) {
    imageError('Image not found or is unreadable.', 'err-imagenotfound.gif');
    }

    if ($im = get_image($imgfile)) {

    $w = imagesx($im);
    $h = imagesy($im);

    // Rotate image if possible
    $exif = exif_read_data($imgfile,0,true);
    $ort = $exif['IFD0']['Orientation'];
    switch($ort)
    {
    case 1: // nothing
    break;

    case 2: // horizontal flip
    break;

    case 3: // 180 rotate left
    break;

    case 4: // vertical flip
    break;

    case 5: // vertical flip + 90 rotate right
    break;

    case 6: // 90 rotate right
    if ($w>$h) { $im = imagerotate($im, 270, 0);}
    break;

    case 7: // horizontal flip + 90 rotate right
    break;

    case 8: // 90 rotate left
    if ($w>$h) { $im = imagerotate($im, 90, 0);}
    break;
    }

    $w = imagesx($im);
    $h = imagesy($im);

    // Give the sizing dimension to $dim
    if (!empty($size)) {
    $dim = $size;
    $width = $height = false;
    } else if (!empty($width) && !empty($height)) {
    $ratio_in = $h / $w;
    $ratio_out = $height / $width;

    <--- it's the same to the end of the file --->
  • Why don't you add this code to the ticket on image rotation. We might decide to use it and make the feature dependent on having PHP 4.3, at least until another solution is availabe.

    Best is to make the changes against the SVN or nightly build and post a patch file. If patch files are a problem, just post the modified class-image.php and function-image.php files.

    I may not get to this right away, I'm going to be in the Galapagos for a couple of weeks.
  • Ok I'll have to write something up. This isn't the most efficient code and I wouldn't want to see this code included in any builds! That's the last thing I want is for Zenphoto to be bogged down by my code ;) Like I said this is just a hack for me.

    The call for the exif orientation is called in every page so it seems very inefficient to me. I would use the zp database information but I'm not sure how to call it and even so the data for EXIFOrientation is a string of words. So either the EXIF module in ZP has to be restructured or a compromise thought out.
  • vraa Member
    I am not too proficient at coding
    But I will try to adapt your code into my site as well
    I would love for the more knowledgeable devs to just know that I'd love for them to check / optimize it and include it in a future release
    I believe PHP4 will be depreciated in 90 more days no?
  • Hi there, sorry for opening this old can of worms ... ;-)
    And my apologies if I missed that topic somewhere, I followed tags and search.

    from trac:
    09/28/07 19:25:51 changed by sbillard
    "Wouldn't it be better to rotate the images before uploading them? If zp does it won't it have to do so each time the image is displayed/referenced? On the principle of doing work at the earliest point, at the vary least the rotation should be done permanantly upon discovery of the image. Don't know what suport there is for that, though."

    I do agree, but wouldn't be the caching mechanism of some help here?

    Since you mentioned doing the rotation manually before uploading:
    I can't help myself but repeating that I really started to like zenphoto. Being not even a sloppy coder it gave me a good kickstart to quickly provide the images I did online.
    And I have a lots of things left to do, everything is set up very basically atm - just to be fast.

    My current workflow now even skips colour correction (colour space etc.) - so currently my pics literally go online from the SD-card (I share the photos with the curating team of a big festival going on here this weeks).
    So the remaining thing is image orientation which is a bit of a pain in this context.

    Did I miss something or do I have to know anything before I start to incorporate the above code? (while _not_ being a software specialist)

    Thanks a lot! Michael.
  • PS: @vraa
    Current requirements:
    PHP 4.10+ with GD support,
    MySQL 3.23+

    vs.

    "The PHP development team hereby announces that support for PHP 4 will continue until the end of this year only. After 2007-12-31 there will be no more releases of PHP 4.4. We will continue to make critical security fixes available on a case-by-case basis until 2008-08-08. Please use the rest of this year to make your application suitable to run on PHP 5. "

    is _not_ a bad thing! My provider runs php5 and MySQL 5 and (so far) I didn't experience any trouble here.
    I'm sure many sites still run php4 for good reasons and are happy to be able to use zp (but I'd update anyway at least for security maintenance).
    Michael.
  • PPS: I just realised that the milestone for rotation is V 1.3 ...
  • ok, later I'll try to patch with this:
    http://www.zenphoto.org/trac/attachment/ticket/111/exif_rotation.patch ;-\

    But I'm not sure if this works with 1.2 by now?
  • I just sat down to apply the patch (manually) and noticed that the provided patch info doesn't match the 1.2.1 code I have installed.
    Just based what I can see on the diff I thought it should work nevertheless, looked for the proper place where to insert but unfortunately it fails.
    Pics and thumbs are just not displayed.
    What code is the patch referring to?
    The patch is 3 months old and I see code lines with "video", 1.2.1 was released on Oct. 1st and looks different.
    I'd appreciate any pointer to speed up my seeking.
    Thanks a lot, Michael.
  • Does it make sense to take the most recent nightly build?
    But then again it's not considered as "stable" - so for the production system it wouldn't be of any help anyway.
    Is the postet rotation patch supposed to work with 1.2.1?
    If so I'd have to re-re-check my patching.
    A tiny hint would be nice as I'm not a php-guy and feel a bit lost with that now ... :-/
  • The nightly builds have not gone through extensive testing, so there may be new problems introduced in them. That said, they tend to be stable. So, generally I would recommend using the nightly builds when doing new implementation. That way you avoid having to do it twice.

    As to the production system. If you have tested the nightly build and it seems to work there is no reason not to use it for production. My site is using a nightly build in production. I don't upgrade it for each fix, but when there are things in the nightly that are improtant to the site the site goes to the nightly build.
Sign In or Register to comment.