-
The Previous Posting
« Utilizing GZip with... -
The Next Posting
Disable Microsoft Software... »
Force Nextgen Gallery To Crop Thumbnails From The Top Of The Image... **Updated**

In our original post, we simply deleted a line to change the starting position of NextGEN’s thumbnail crop. With the most recent version of NextGEN Gallery,1.4.3 at the time of this update. While this was a functional fix, it was generating errors. So here’s our much improved, and clean fix.
First locate the code below. Its currently located at line #270, in the file (plugins\nextgen-gallery\admin\functions.php). Take note that at the time of this posting “Our” html editor shows this on line #270. But this will vary not only between releases made by the plugins developer, but also by things like your html editor displaying text double spaced. Search features can also save you time in this area.
270 271 272
// get optimal y startpos $ypos = ($thumb->currentDimensions['height'] - $ngg->options['thumbheight']) / 2; $thumb->crop(0, $ypos, $ngg->options['thumbwidth'],$ngg->options['thumbheight']);
And change that code to the following.
270 271 272
// get optimal y startpos $ypos = ($thumb->currentDimensions['height'] - $ngg->options['thumbheight']) / 2; $thumb->crop(0, null, $ngg->options['thumbwidth'],$ngg->options['thumbheight']);
You’ll notice that all we did we did was change the starting position of the crop, by changing “$ypos” to “null”. And wallah, thumbnail crops start from the top.
In turn, you could also crop the images from the bottom by changing the code from.
270 271 272
// get optimal y startpos $ypos = ($thumb->currentDimensions['height'] - $ngg->options['thumbheight']) / 2; $thumb->crop(0, $ypos, $ngg->options['thumbwidth'],$ngg->options['thumbheight']);
To...
270 271 272
// get optimal y startpos $ypos = ($thumb->currentDimensions['height'] - $ngg->options['thumbheight']) / 1; $thumb->crop(0, $ypos, $ngg->options['thumbwidth'],$ngg->options['thumbheight']);
The change here is the math integer. We changed / 2, or divide by two, to / 1 or divide by one. If we had an image of 700px, the original coding would tell the crop to originate from the center, or half of 700. We’ve changed that to 1, telling it to originate the crop from the bottom or 700.
Hope this helps someone. Let use know by leaving a comment.
Our original post......... Do not use the following code in an active site. This is only here to display a history of edits. As well as to provide a code cleanup base from use of dated code.
We recently finished a custom themed photo gallery for a client utilizing the NextGen Gallery plugin. NextGen is an amazingly well rounded plugin with loads of options and configurations. One major complaint our client had about NextGen was that the thumbnails were generated in a way that was chopping the top off the image. A large majority of his images are portrait shaped, taller than wide, and required that the top be visible in the thumbnail image.
After searching through the WordPress and NextGen forums, we we’re still coming up empty handed. So we started digging around in the code. We eventually came to the following line. The following code tells Nextgen to center the thumbnail crop at half the Y Position, height divided by two, or the center of the picture vertically. So we just deleted it, and now the crop starts from the top of the picture. Problem fixed. Now our client doesn’t have to manually resize each thumbnail, making him a happy client.
location: [your plugin folder]/nextgen-gallery/admin/functions.php
Line# 289
289
$ypos = ($thumb->currentDimensions['height'] - $ngg->options['thumbheight']) / 2;
The most recent Google source code shows this at line #288. So be sure to pay attention to which line you delete.
This works absolutely fine. Is there any way we can edit the code to resize full images to thumbnail like TimThumb script does instead of cropping from top or bottom.
Brilliant, and that fixed our issue, thanks for posting this up guys!
cheers
K&B
Thanks, this worked perfectly! Easy fix. Perhaps you should mention the file to change (functions.php) in your revised text at the top. I had to go back and reread the article - I had skipped the part about the old version, where the file was mentioned...