Adding the autorotate filter to an image style gives the following error:

Warning: exif_read_data(2011-05-31_05-51-58.jpg): Error reading from file: got=x3FFA(=16378) != itemlen-2=x779C(=30620) in imagecache_autorotate_image() (line 94 of /home/www/drupal7/drupal-7.8/sites/all/modules/imagecache_actions/autorotate/imagecache_autorotate.module).
Warning: exif_read_data(2011-05-31_05-51-58.jpg): Invalid JPEG file in imagecache_autorotate_image() (line 94 of /home/www/drupal7/drupal-7.8/sites/all/modules/imagecache_actions/autorotate/imagecache_autorotate.module)

The filter doesn't work on any image.

Comments

yelvington’s picture

Verified, clean install.

Warning: exif_read_data(P1010582.JPG): Invalid JPEG file in imagecache_autorotate_image() (line 94 of /web/sitename/htdocs/sites/all/modules/imagecache_actions/autorotate/imagecache_autorotate.module).

yelvington’s picture

This is probably the more interesting error message:

Warning: exif_read_data(P1010582.JPG): Error reading from file: got=x3FFA(=16378) != itemlen-2=x7D9A(=32154) in imagecache_autorotate_image()

I get this logged immediately before the "invalid JPEG file" message. The numeric values are identical on multiple images.

yelvington’s picture

Apologize for spamming this issue, but the PHP documentation http://php.net/manual/en/function.exif-read-data.php says "The name of the image file being read. This cannot be an URL." Does this work with the public://filename stream wrapper?

yelvington’s picture

StatusFileSize
new1.56 KB

OK, there are two problems with this module. One is the stream wrapper problem, which can be fixed by handing the stream uri to drupal_realpath in line 94:
$exif = exif_read_data(drupal_realpath($image->source));

Once you do this, the action fails because D7 has renamed imageapi_image_rotate. In line 115:
image_rotate($image, $degrees);

Being too lazy to wrestle with patch, I've attached a fixed version of the file imagecache_autorotate.module.

yelvington’s picture

Priority: Normal » Critical
Status: Active » Needs review
millionleaves’s picture

This fixed version has resolved the issue I was having. Basically, the image wasn't being created if it needed to be rotated. It is now.

Caveat: When troubleshooting, I didn't find any errors in the Drupal log and didn't dig any deeper, so I can't be sure that this hasn't introduced any new issues.

wonder95’s picture

Status: Needs review » Reviewed & tested by the community

Confirmed that both this issue happens and the "patch" works for me.

wonder95’s picture

StatusFileSize
new1.69 KB

Hmmm, it looks like this fix was already partially applied here. However, the 7.x-1.x branch still has the invalid call to image_rotate_effect(). The attached patch cleans up the unnecessary $realpath variable definition and changes this incorrect call

image_rotate_effect($image, array('degrees' => $degrees));

to

image_rotate($image, $degrees);
fietserwin’s picture

Version: 7.x-0.0 » 7.x-1.x-dev
Priority: Critical » Major
Status: Reviewed & tested by the community » Fixed

Added your change plus some more changes:
- parameter passing to image_autorotate failed as it expects separate parameters, not an array with parameters.
- added error handling for the case whne the PHP exif extension is not enabled.
- dimensions callback setting was missing for the effect info.
- failed to alter current dimensions on a 90 or 270 degrees rotation with imagemagick.

The latter is a bug in imagemagick toolkit. I will create a separate issue over there.

fietserwin’s picture

Related issue in imagemagick toolkit: #1551262: Rotate should alter dimensions.

wonder95’s picture

@fietserwin, did you mean to attach a patch? I don't see one from you.

fietserwin’s picture

Committed... I am the new co-maintainer.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.