Installing a modern jpegtran binary for Gallery2


I probably should add a tutorial content type already.

Okay, I was having problems with a new gallery2 install not rotating resized images correctly. I didn't have the correct software installed on my system, and gallery2 really isn't supported on Ubuntu systems later than, say, 2007, so, this install is a less than desirable configuration in many ways. I really can't stand Gallery3, and dislike the style of focusing on a single photo, leaving a photo stream as a second class citizen, of other gallery packages I tested, so back to the somewhat bloated world of gallery2.

Which wasn't quite working. No rotating.

Blah blah blah. The fix:

Install the jpegtrans binary:

$ sudo apt-get install libjpeg-progs

It'll likely be version 8d.

In the gallery install, In the file modules/jpegtran/classes/JpegtranToolkitHelper.class, around line 141, change this line:

  if (preg_match("/Independent JPEG Group's JPEGTRAN/", $line)) {

to this line:

  if (preg_match("/Independent JPEG Group's/", $line)) {

Yay! Code is now updated to work with the current jpegtran binary! Configure it in gallery2 by going to Site Admin > Plugins at main.php?g2_view=core.SiteAdmin&g2_subView=core.AdminPlugins in your gallery2 install.

Activate the module by adding the jpegtran binary path, then enable the module.

Clear the image cache by going to lib/support/index.php in the gallery2 install, and clearing the thumbnail / resized image cache. Bleh.

I think this solved my problem. I'll find out at some other point soon, I guess. I also tried this solution, which involves exiv2, so I'm uncertain which did what.


1) Go to my gallery data directory with a command line. Then move to the albums directory.
2) Make sure I have the exiv2 utility installed.
2) Find all jpg files and run this exiv2 command script which resets the exif orientation info.
find . -iname '*JPG' -print0 | xargs -0 -n1 sudo exiv2 -v -m ~/exivcmd -k modify
---- exifcmd file ----
set Exif.Image.Orientation 1
set Exif.Thumbnail.Orientation 1
---- exifcmd file ----
3) Use a browser to get to my gallery maintenance page. Something like The password is in your config.php file.
4) Click on Cache Maintenance.
5) Select Cached HTML pages, Albums and Photo Data, and Thumbnails and Resizes.

Voila, all of my pictures show up correctly on my desktop, iPhone and iPad.

Add new comment