Member
Member
christue   05-05-2010, 10:25
#1

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?

Administrator
Administrator
acrylian   05-05-2010, 11:25
#2

Well, I doubt that normal standard shared hosts where Zenphoto mostly is used provide something special like "jpgtran" (I never heard about before actually).
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.

Member
Member
christue   05-05-2010, 15:54
#3

Acrylian, thanks for your answer.

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...

Member
Member
gjunk   06-05-2010, 02:43
#4

Apolagize for this being slightly OT - but what if the exif data is missing or incorrect (which certainly happens).

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

Member
Member
sbillard   06-05-2010, 03:51
#5

sometimes it is just best to look. If your PHP supports image rotation you will have that selection on the image edit tab. You can pick whatever rotation you wish. Only images that Zenphoto creates are rotated (the original is almost never touched. Just by the crop-image plugin and then with appropriate warnings.)

Member
Member
christue   06-05-2010, 09:22
#6

One question to the developers: When I have a _Image object, what would be the best practice to determine whether it is a JPEG image? I'm missing a function like $image->getType() that would return "image/jpeg". So do I have to check the extension of the filename?

Administrator
Administrator
acrylian   06-05-2010, 10:19
#7

We don't have a method for that. But the suffix should match the file type anyway so we have a convenient function to do this:
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.

Member
Member
christue   06-05-2010, 11:10
#8

Thanks acrylian, I now use

in_array(getSuffix($image->localpath), array('jpg', 'jpeg', 'JPG', 'JPEG'));

Member
Member
christue   06-05-2010, 16:17
#9

OK, there's a first version of my first zenphoto plugin. There's currently no homepage for it, but the code can be fetched from Gitorious:

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
Administrator
Administrator
acrylian   06-05-2010, 16:27
#10

Would it be possible to add these notes on the gitorious page as well? Just asking as that is perfect for a plugin project page of course.

I will create a entry on the extensions page for it linking to both urls for now.

Member
Member
christue   06-05-2010, 16:56
#11

I'm new to gitorious and didn't find a way to edit some text on the linked page... But now I found that I can create a wiki in my project there and so I put the plugin documentation to the following wiki page:

http://gitorious.org/zenphoto-plugins/pages/Filter-jpegrotate-lossless

Member
Member
christue   06-05-2010, 17:15
#12

On the wiki page
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.

Administrator
Administrator
acrylian   06-05-2010, 17:25
#13

Great, I was sure that must have been possible. The entry is up: http://www.zenphoto.org/2010/05/filter_rotation_lossless/

Member
Member
nehakakar   21-10-2024, 08:27
#14

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.

  
Powered By MyBB, © 2002-2026 MyBB Group.
Made with by Curves UI.