Gallery 3 Super-Large Thumbnails

Problem: The G3 RC2 Gallery,…

Login

Blog History

Problem:
The G3 RC2 Gallery, in album view, displays random `thumbnails' that are full sized. (e.g. the size of the real photo).

Cause
I am trialling Gallery 3 RC2 hosted on Dreamhost shared hosting.

I think the way Gallery 3 generates thumbnails is that it takes the full sized image from where it is stored for example $g3_root/var/albums/albumname/picture.jpg and using imagemagick or whichever graphic toolkit is available converts the full sized image to a thumbnail in $g3_root/var/thumbs/albumname/picture.jpg.

However on a shared hosting platform such as Dreamhost's the webserver will kill any process that uses either too much RAM or CPU.

After noting the super-sized thumbnail issue and getting in contact with Dreamhost they informed me that my G3 installation was indeed having it's processes killed because they were using too much RAM.

So G3 was transferring a full size image to the thumbs directory and before it has a chance to convert it to a thumbnail the process is being killed by the webserver. The effect of this was that I was getting full sized images in the thumbs directory.

Work-a-round
I have a temporary work-a-round (other than getting a Virtual Private Server account which has gauranteed protected resources) to convert the unfinished thumbnails to the correct size:

Firstly you need a shell account so you can log in and work stuff from the command line.


# you can find full sized images by doing a ls -alh and looking for extra-large images

# identify the size of a good thumbnail (here it's 150x113 pixels)
[mydhbox]$ identify IMGP0197.JPG
IMGP0197.JPG JPEG 150x113 150x113+0+0 DirectClass 8-bit 34.9336kb

# identify the size of the bad thumbnail (2304x3072 pixels)
[mydhbox]$ identify IMGP0201.JPG
IMGP0201.JPG JPEG 2304x3072 2304x3072+0+0 DirectClass 8-bit 661.613kb

# use mogrify to resize the huge thumbnail in-place.
[mydhbox]$ mogrify -resize 150x150  IMGP0201.JPG

# check it
[mydhbox]$ identify IMGP0201.JPG
IMGP0201.JPG JPEG 113x150 113x150+0+0 DirectClass 8-bit 36.4512kb

# or do it in one hit !!! 
# Be careful I'm not a great one line bash script writer and I haven't tested this for robustness
# if you run it in the wrong directory (other than $g3_root/var/thumbs) 
# you could resize your album photos and not the thumbnails
# it may bork your g3 installation
find . -type f | xargs  -IFILE identify -format "%d/%f:%h %w" "FILE" | grep -v 150 | cut -d: -f1 | xargs -IFILE mogrify -resize 150x150 "FILE"

# the above means
# find all files of type file in the current directory and below
# pipe the result to xargs and use identify to print out the directory/file and the height and width 
# using grep give me a list of any thumbnails that don't(-v) have one dimension of 150pixels
# you may need to adjust this so you have the correct thumbnail dimension for you gallery installation
# once you have a list of the large thumbnails cut the path/file and pipe it to xargs and mogrify to do an inplace resize


You also need to upudate the items table in the G3 database because the thumb_height and thumb_width values may be wrong also. Note:Don't do this if you don't have a good idea of what you are doing and backup your database before attempting this


/* WE SET THE LARGE THUMBS HEIGHT DIMENSION 
    BACK TO THE CORRECT LENGTH BUT ONLY
    IF IT'S THE LONGEST SIDE
    FOR EXAMPLE IF THE DB SAID THE THUMB 
    HEIGHT and WIDTH WAS 800 x 600
    SET THE THUMB_HEIGHT TO 150 BUT 
    ONLY IF THE HEIGHT IS LONGER THAN THE WIDTH
*/

UPDATE `items` SET `thumb_height` = 150 
WHERE `type` = 'photo' AND
`thumb_height` > `thumb_width` AND 
`thumb_height` > 150

/* NOW SET THE WIDTH OF THOSE THUMBS 
    WE HAVE JUST CHANGED TO THE CORRECT WIDTH VALUE */
UPDATE `items` SET `thumb_width` = 113 
WHERE `type` = 'photo' AND
`thumb_width` > 150 AND
`thumb_height` = 150

/* You may have to run a few more queries to get it fixed but that is left as an excercise for the reader */

3 Comments

  1. Reza

    I was having the same problem on my shared Dreamhost account. I found this plugin that rebuilds images in a specific album in case you don't want to go through the trouble of running commands and manually editing the database.

    I still use the first half of your one liner to detect which albums to rebuild though, It's good stuff

    Reply
    • admin

      Thanks Reza. I will install this for my Gallery too. It sounds a lot easier than doing it by hand. Hopefully Dreamhost will bump their memory limits up a little for Gallery 3 installs so that the default G3 resize operations complete in future without being killed off by the server and leaving supersized thumbs and resizes in G3.

      [WORDPRESS HASHCASH] The poster sent us '0 which is not a hashcash value.

      Reply

Trackbacks/Pingbacks

  1. Shared Hosting has Limitations – The Telarah Times - [...] 3 keeps getting it’s imagemagick resize processes knocked on the head and I end up with mega large thumbnails…

Submit a Comment

Your email address will not be published. Required fields are marked *

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

The reCAPTCHA verification period has expired. Please reload the page.