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 at the time of this update. While this was a func­tional fix, it was gen­er­at­ing errors. So here’s our much improved, and clean fix.

First locate the code below. Its cur­rently located at line #270, in the file (plugins\nextgen-gallery\admin\functions.php). Take note that at the time of this post­ing “Our” html edi­tor shows this on line #270. But this will vary not only between releases made by the plu­g­ins devel­oper, but also by things like your html edi­tor dis­play­ing text dou­ble spaced. Search fea­tures 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 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......... Do not use the fol­low­ing code in an active site. This is only here to dis­play a his­tory of edits. As well as to pro­vide a code cleanup base from use of dated code.

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:


3 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

  3. Antonella says:

    Thanks, this worked per­fectly! Easy fix. Per­haps you should men­tion the file to change (functions.php) in your revised text at the top. I had to go back and reread the arti­cle - I had skipped the part about the old ver­sion, where the file was mentioned...

Leave a Comment