Jump to content

TRICK - Crop images inside preserve ratio (no white spaces arround image)


Recommended Posts

Hello and sorry form my english.

Searching a metod for clean the white spaces for the images i probe this and run ok.
In admin/functions.php change arround the line 197 change the simbol > for <.
The crop images dont show withe spaces (crop outside) and generate a proportional images fill all the type images (small, large, etc...) (crop inside)

I probe in V1.0.


Original:

if (intval(Configuration::get('PS_IMAGE_GENERATION_METHOD')) == 2 OR (intval(Configuration::get('PS_IMAGE_GENERATION_METHOD')) == 0 AND $widthDiff > $heightDiff))



Modified:

if (intval(Configuration::get('PS_IMAGE_GENERATION_METHOD')) == 2 OR (intval(Configuration::get('PS_IMAGE_GENERATION_METHOD')) == 0 AND $widthDiff < $heightDiff))



Sorry sorry for my english. (im spanish)

Link to comment
Share on other sites

  • 8 months later...

Wanted to follow up. I'm using Prestashop 1.2.5.0, while the fix worked for the image resizing, when I went back and clicked on "catalog" in the admin area it failed to list products. This hack will break product management functionality in the backend this way... Will see if I can figure out a way around it as it was resizing images properly... Antuan any ideas?

Link to comment
Share on other sites

Very strange, changed:

    if (intval(Configuration::get('PS_IMAGE_GENERATION_METHOD')) == 2 OR (intval(Configuration::get('PS_IMAGE_GENERATION_METHOD')) == 0 AND $widthDiff > $heightDiff))



to:

       if (intval(Configuration::get('PS_IMAGE_GENERATION_METHOD')) == 2 OR (intval(Configuration::get('PS_IMAGE_GENERATION_METHOD')) == 0 AND $heightDiff > $widthDiff))



and it now seems to be working... Hope this helps anyone having similar issues

  • Like 1
Link to comment
Share on other sites

  • 1 month later...
  • 3 months later...

Hello, could anyone give me a hint on how exactly this works ?

I'm under v1.2.5 and changed the line in images.inc.php file.

When I regenerate the pictures, the white space is still there as if it had no impact.

Any help would be much appreciated.

I'm desperately trying to find a solution for the product image background to not have white stripes around the cropped image.

Link to comment
Share on other sites

  • 4 months later...
  • 3 weeks later...
  • 1 month later...
  • 1 year later...

Thank you, Its work.

And for the resizing of image as is what we want, you can combine or trying switch the ">" into "<"

because, i'll try the first option, but the image not cropping following the image frame, and then i try to switch the mark above vise verse and success the image fit on the frame and the background not white.

Link to comment
Share on other sites

  • 5 weeks later...

Hello. :)

I'm from Russia sorry for my bad English. The method works for prestashop version 1.4.6.2. Only have to change another Fail - images.inc.php

 

Change the sign of

 

if (Configuration:: get ('PS_IMAGE_GENERATION_METHOD') == 2 OR (! Configuration:: get ('PS_IMAGE_GENERATION_METHOD') AND $ widthDiff <$ heightDiff))

 

on

 

if (Configuration:: get ('PS_IMAGE_GENERATION_METHOD') == 2 OR (! Configuration:: get ('PS_IMAGE_GENERATION_METHOD') AND $ widthDiff > $ heightDiff))

 

If there are programmers or administrators interested I would like to add the ability to select a panel or module.

 

On

 

 

if (Configuration::get('PS_IMAGE_GENERATION_METHOD') == 2 OR (!Configuration::get('PS_IMAGE_GENERATION_METHOD') AND $widthDiff < $heightDiff))

 

If there are programmers or administrators interested I would like to add the ability to select a panel or module.

 

Sincerely Demos

Link to comment
Share on other sites

  • 1 month later...
  • 1 month later...
  • 2 months later...

Can't prestashop provide some features like:

 

Background-Color: #xxxx

Rectangle-crop: yes/no

crop-position: top/left/...

 

This is all hardcoded :-(

 

This is a feature-wish, don't know where to post elsewhere

Link to comment
Share on other sites

  • 1 month later...

Hi just coming back to this thread.

 

I have tried the above but it simply crops out the left and right sections of my landscape images so that they are square. I simply want landscape images with *no* white border at the top and the bottom. Surely this is possible somehow?

Link to comment
Share on other sites

  • 1 month later...
  • 6 months later...
Very strange, changed:

 if (intval(Configuration::get('PS_IMAGE_GENERATION_METHOD')) == 2 OR (intval(Configuration::get('PS_IMAGE_GENERATION_METHOD')) == 0 AND $widthDiff > $heightDiff))

 

to:

if (intval(Configuration::get('PS_IMAGE_GENERATION_METHOD')) == 2 OR (intval(Configuration::get('PS_IMAGE_GENERATION_METHOD')) == 0 AND $heightDiff > $widthDiff))

 

and it now seems to be working... Hope this helps anyone having similar issues

 

Thanks a lot, works fine with PS 1.4.2.5 :)

Link to comment
Share on other sites

  • 8 months later...
  • 11 months later...

This works for Prestashop 1.6.0.9 BUT

 

only for new uploads, If then I regenerate images on back office doesn't work, back to fill with white...

 

In Prestashop 1.6 you will found the code lines in /classes/ImageManager.php

for me was the line 166

 

Only I changed

 

$width_diff > $height_diff

 

for

 

$width_diff < $height_diff

Edited by sg1_anhell (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 7 months later...
  • 1 year later...
  • 5 years later...

Since this topic pops up if you google on how to remove the white bars; I'd thought I'd write my solution for PrestaShop 1.7 here.
Works for both formats, so portrait and landscape.
 

Step 1:

Open the following file:

/classes/ImageManager.php

Go to the line

if ($fileType == 'png' && $type == IMAGETYPE_PNG) {

and remove the last bit, so that it looks like:

if ($fileType == 'png') {

 

Step 2:

In your Backoffice, go to

Design > Image Settings

and set Image Format to Use PNG for all images

  • Like 1
Link to comment
Share on other sites

  • 2 years later...
On 11/23/2021 at 6:06 PM, m-v-d said:

Since this topic pops up if you google on how to remove the white bars; I'd thought I'd write my solution for PrestaShop 1.7 here.
Works for both formats, so portrait and landscape.
 

Step 1:

Open the following file:

/classes/ImageManager.php

Go to the line

if ($fileType == 'png' && $type == IMAGETYPE_PNG) {

and remove the last bit, so that it looks like:

if ($fileType == 'png') {

 

Step 2:

In your Backoffice, go to

Design > Image Settings

and set Image Format to Use PNG for all images

Any other solution to keep using JPG? Using PNG for product images is a bad idea because of the large image size.

White borders in product pictures in mobile view are a bad idea.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...