Center Cropping Not Working

Permalink Browser Info Environment
I'm using this plugin, but the images are not being cropped to the center. It's not exactly all to the left or right either. It's left of center really, but off enough that it's noticeable (by my client!). Could you give me any input on this? I can grant access to the site where it's being used if that helps.

Type: Discussion
Status: New
facerX
View Replies:
jordanlev replied on at Permalink Reply
jordanlev
Hi Jared,
Here's how you can fix that: on your server, edit this file:
packages/deluxe_image_gallery/helpers/deluxe_image_gallery.php


Down near line #116 you will see some code like this:
if ($cropWidth) {
   //Get half the difference between scaled width and target width,
   // and crop by starting the copy that many pixels over from the left side of the source (scaled) image.
   $nudge = ($newWidth / 10); //I have *no* idea why the width isn't centering exactly -- this seems to fix it though.
   $src_x = ($scaleToWidth / 2.00) - ($newWidth / 2.00) + $nudge;
}
if ($cropHeight) {
   //Get half the difference between scaled height and target height,
   // and crop by starting the copy that many pixels down from the top of the source (scaled) image.
   $src_y = ($scaleToHeight / 2.00) - ($newHeight / 2.00);
}


Replace that chunk of code with this:
//Calculate cropping to center image
if ($cropWidth) {
   $src_x = round(($originalWidth - ($newWidth * $originalHeight / $newHeight)) * 0.5);
}
if ($cropHeight) {
   $src_y = round(($originalHeight - ($newHeight * $originalWidth / $newWidth)) * 0.5);
}


I think that should work -- let me know if it doesn't and I'll try to fix it.

-Jordan
facerX replied on at Permalink Reply
facerX
That didn't work. It didn't break anything either, but the images are still cropped the same.
jordanlev replied on at Permalink Reply
jordanlev
Hmm... I think that might be due to C5 having cached the old images. Can you do me a favor and add a new gallery block to a page, using the same file set as one of the existing ones -- let me know if the crop is different on that new one or not.

Thanks.
jordanlev replied on at Permalink Reply
jordanlev
Actually, I just realized that the caching will stay in effect even for a new block (if it's using the same images).
How many images in total are we talking about here?
facerX replied on at Permalink Reply
facerX
Hundreds. I cleared the C5 cache the first time I tried. I just tried deleting/adding the block. No luck.
jordanlev replied on at Permalink Reply
jordanlev
Okay. Sorry this is getting so complicated. First I'd like to make sure the new cropping works for you. Can you do a little test and upload a new image to the site and put that in a gallery, and let me know if the centering is correct?

Once we've established that, then we can take care of the image cache (which is different I guess than just "clearing the cache" from sitewide settings).

Thanks for your patience.

-Jordan
facerX replied on at Permalink Reply
facerX
Bingo. New upload of the same pic did the trick. How can I blow out the cache without re-uploading all the pictures?
jordanlev replied on at Permalink Reply
jordanlev
I think I have a relatively easy solution, but I'm waiting to hear back from the C5 guys as to whether it will actually work. If not, I have a more complicated solution in mind, but hopefully I hear back from them soon and we can get this taken care of. I'll be in touch.

-Jordan
jordanlev replied on at Permalink Reply
jordanlev
Hey Jared,
Unfortunately the "easy way" doesn't actually clear the image cache. You're going to need to delete the image cache on your server. This is relatively safe to do but will mean that the system has to re-generate all of the file thumbnails on your site, which will make page loads slow down the first time.

So what you want to do is delete everything inside the "YOURSITE/files/cache/" directory (make sure you're inside the "cache" directory -- you should see mostly just a bunch of jpg's and png', NOT subdirectories). Then you should visit each page that had an image gallery in it in your web browser. Depending on how large the images are and how many there are on a page, it may take a few seconds to load -- but this is just because the system is re-generating the thumbnails and all subsequent page loads will go back to the normal amount of time.

Let me know if this makes sense to you or if you'd like me to explain it in more detail (or if you're not sure how to access your files/cache directory via FTP).

-Jordan
jordanlev replied on at Permalink Reply
jordanlev
FYI, this centering issue has been addressed in the most recent version of Deluxe Image Gallery (1.0.4)

concrete5 Environment Information

Browser User-Agent String

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You have not specified a license for this support ticket. You must have a valid license assigned to a support ticket to request a refund.