First of all I want to thank the developers for this wonderful piece of software! I have been searching for a web gallery management tool and ZenPhoto is just what I was looking for...
What I don't like very much is the way the auto-rotating feature of images works:
- rotation should use a lossless jpeg rotation tool like "jpegtran", if it is available on the server
- IMHO, rotation should be done once when importing the image (and, of course, when a rotation is requested by the admin-edit script), but not every time when generating scaled cache images
Has anyone already considered to implement this?
I would like to try it. When looking in the code for a place to hook in rotation after import I came across the "new_image" filter. Would this be the right place for such an rotation filter or do you expect problems?
Comments
Image rotation is actually only done if the EXIF data of an image suggests that. But I am not the expert on these parts. Note that Zenphoto normally uses the scaled images for display, not the full ones.
Anyway, of course feel free to write a plugin or admin utility for your special needs. New third party plugins are always welcome. The new_image filter is surely the tool to use for this. Lets us know and we surely add an entry to our extensions section. Please read the contributor and developer guidelines before proceeding.
jpegtran is part of the Independent JPEG Group's software (libjpeg) which is used for jpeg support in many applications and should be available on almost every linux system (in Debian/Ubuntu, it is in the package libjpeg-progs). I believe that many image viewers use it for jpeg rotation.
What makes jpegtran special is that it does not decompress the image, rotate it and then compress it again (loosing quality), but simply rotates the compressed image, so the jpeg image will not loose quality. That's why it could safely be hooked in to zenphoto right when importing images to rotate the ORIGINAL image.
Of course, the image should only be rotated if the EXIF orientation value suggests this. And afterwards the EXIF orientation flag must be set to 1 so that the image will not be rotated again...
I'm now working on a plugin for zenphoto that does the following things:
- register filter function for image_new
- if exif orientation of the image is greater than 1:
- rotate image file using jpegtran (if available on the server)
- update exif information in image file (set orientation to 1),
- update EXIFOrientation (set to 1) and height / width in _Image object (database)
I hope to publish a first version soon...
Is there a way for admin to request a rotation (for display purposes)
Am I correct that rotations and edits are for display only and leave the original image intact ?
Thanks!!
gene
http://www.zenphoto.org/documentation/functions/_functions-basic.php.html#functiongetSuffix
If you need to get the mimetype `functions-rss.php` (not on the documentation) has a `getMimeType($ext)` that covers all standard files Zenphoto supports. You probably have to include that file into your plugin to use it.
But maybe sbillard has another answer as this core stuff is generally his resort.
`in_array(getSuffix($image->localpath), array('jpg', 'jpeg', 'JPG', 'JPEG'));`
http://gitorious.org/zenphoto-plugins/filter_jpegrotation_lossless
What it does currently:
When importing JPEG images to an album, this filter checks for the EXIFOrientation value and when this value suggests that the image must be rotated, it rotates the image and updates the EXIFOrientation value accordingly, so that the image will not be rotated again.
Requirements:
- jpegtran executable must be available on the server (http://jpegclub.org/, Debian/Ubuntu: "sudo apt-get install libjpeg-progs")
- put the plugin files (file "filter-jpegrotation-lossless.php" and folder "filter-jpegrotation-lossless" with all it's contents) into your zenphoto/plugins folder
- plugin must be enabled
- in the plugin settings for filter_jpegrotation_lossless you must explicitly enable auto rotation on import, and you must specify the path to jpegtran on your system
Notes:
- Unlike the traditional auto_rotate feature of Zenphoto, this filter alters the original uploaded image! Normally, this should do no harm because the rotation is lossless and can be repeated without loosing image quality.
- There is no problem if auto_rotate in Zenphoto is enabled: it simply does nothing if the image is already rotated.
Not yet implemented:
- Manual lossless rotation of images in the admin/edit interface
I will create a entry on the extensions page for it linking to both urls for now.
http://gitorious.org/zenphoto-plugins/pages/Filter-jpegrotate-lossless
http://gitorious.org/zenphoto-plugins/pages/Filter-jpegrotate-lossless
I added links to download / clone the source code, so the entry in the extensions page needs only to link to this page. And the pluginURL in the plugin itself now links to this page, too.
It's exciting to see efforts for lossless JPEG rotation in ZenPhoto! Using tools like https://jpegcompressor.com can also help optimize images without losing quality, making it easier to manage image files.