Force Nextgen Gallery To Crop Thumbnails From The Top Of The Image... **Updated**

wordpress-glossy
In our orig­i­nal post, we sim­ply deleted a line to change the start­ing posi­tion of NextGEN’s thumb­nail crop. With the most recent ver­sion of NextGEN Gallery,1.4.3 as of this post­ings date, this was gen­er­at­ing errors. So we dug around in the code a bit, and here’s our fix.

First locate the code below. Located cur­rently at line #270.

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 the 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 start­ing posi­tion of the crop, by chang­ing “$ypos” to “null”. And wal­lah, thumb­nail crops start from the top.

In turn, you could also crop the images from the bot­tom by chang­ing 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 inte­ger. We changed / 2, or divide by two, to / 1 or divide by one. If we had an image of 700px, the orig­i­nal cod­ing would tell the crop to orig­i­nate from the cen­ter, or half of 700. We’ve changed that to 1, telling it to orig­i­nate the crop from the bot­tom or 700.

Hope this helps some­one. Let use know by leav­ing a comment.

Our orig­i­nal post.........

We recently fin­ished a cus­tom themed photo gallery for a client uti­liz­ing the NextGen Gallery plu­gin. NextGen is an amaz­ingly well rounded plu­gin with loads of options and con­fig­u­ra­tions. One major com­plaint our client had about NextGen was that the thumb­nails were gen­er­ated in a way that was chop­ping the top off the image. A large major­ity of his images are por­trait shaped, taller than wide, and required that the top be vis­i­ble in the thumb­nail image.

After search­ing through the Word­Press and NextGen forums, we we’re still com­ing up empty handed. So we started dig­ging around in the code. We even­tu­ally came to the fol­low­ing line. The fol­low­ing code tells Nextgen to cen­ter the thumb­nail crop at half the Y Posi­tion, height divided by two, or the cen­ter of the pic­ture ver­ti­cally. So we just deleted it, and now the crop starts from the top of the pic­ture. Prob­lem fixed. Now our client doesn’t have to man­u­ally resize each thumb­nail, mak­ing him a happy client. :-)

loca­tion: [your plu­gin 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 atten­tion to which line you delete.


Was this article helpful? Here's a few related articles which may also interest you.

Related Posts:


2 Comments to “Force Nextgen Gallery To Crop Thumbnails From The Top Of The Image... **Updated**”

  1. Sushant says:

    This works absolutely fine. Is there any way we can edit the code to resize full images to thumb­nail like TimThumb script does instead of crop­ping from top or bottom.

  2. K&B says:

    Bril­liant, and that fixed our issue, thanks for post­ing this up guys!

    cheers

    K&B

Leave a Comment