Jump to content

Automatic images cropping for Prestashop 1.5.2 (free override)


adhd_kid

Recommended Posts

Hey guys, recently i've done 2 Prestashop templates that needed the zoom-crop functionality for certain image types ( see timthumb to know what i mean) . My first approach (it was Presta 1.4.x) was to override the The admin tabs and do lots of unneccessary stuff, then the other project came and when i was about to copy my old code i thought of a much better solution, so here it is :

 

0. Read our short introduction and copy code from here:

 

http://www.bazingade...restashop-1-5-2

 

or here (without introduction):

 

http://pastebin.com/eg2tLztL

 

1. Go to Preferences -> Images -> Add new and set the new image size that you want to be zoom-cropped (to fit the whole area)

 

2. Name the new image size adding the "_btt" suffix to it

 

3. regenerate your pictures, use the new picture name in your templates where neccessary and enjoy :)

 

*** In the attachment you will find an example of how should new image size with crop be named in the backoffice

 

**** Remember to actually use the new image size in your templates, like:

 

<img src="{$link->getImageLink($product.link_rewrite, $product.id_image, 'fbmag_btt')}" >

post-230301-0-27897100-1352981128_thumb.png

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

hi!

sorry, no work for me, PS1.5.2

 

You have exemple for configuration image size please?

 

i have write Preferences -> Images -> Add new and set the new image size 600x600 and name "cropsmall_btt"...

 

and I have been save correctly in /overrides/classes/ImageManager.php and regenerate all thumbs... :/

Edited by Vinc3nzo (see edit history)
Link to comment
Share on other sites

Hello,

 

I still do not understand how to use your wits. I change my files. TPL "home_default" and that's it foncitonne wrong, I do not understand the order of manipulations ... What exactly TPL file must be modified?

 

Can disable after "home_default"? or we are obliged to leave?

 

The pictures do not cut the product details on the "THUMBS" on mouseover ... :/

 

Thx you advance! good continuation!

 

 

PS: i have multiple image dimension...

Edited by Vinc3nzo (see edit history)
Link to comment
Share on other sites

Hi Vincenzo, I just think that what you need to do is simple but you need a bit of further explanation. Tomorrow i should be having my day off from work so mail me: [email protected] and i'll see what your page outputs then will tell you what to do exactly so you can write this in your own words for others who might not understand what they need to do here, ok? :)

 

Hello,

 

I still do not understand how to use your wits. I change my files. TPL "home_default" and that's it foncitonne wrong, I do not understand the order of manipulations ... What exactly TPL file must be modified?

 

Can disable after "home_default"? or we are obliged to leave?

 

The pictures do not cut the product details on the "THUMBS" on mouseover ... :/

 

Thx you advance! good continuation!

 

 

PS: i have multiple image dimension...

Link to comment
Share on other sites

  • 3 weeks later...
  • 2 weeks later...

Or...

 

in ImageManager.php

 

repleace:

if (Configuration::get('PS_IMAGE_GENERATION_METHOD') == 2 || (!Configuration::get('PS_IMAGE_GENERATION_METHOD') && $width_diff > $height_diff))

 

to:

if (Configuration::get('PS_IMAGE_GENERATION_METHOD') == 2 || (!Configuration::get('PS_IMAGE_GENERATION_METHOD') && $width_diff < $height_diff))

 

works on 1.5.2

  • Like 2
Link to comment
Share on other sites

  • 4 weeks later...

Or...

 

in ImageManager.php

 

repleace:

if (Configuration::get('PS_IMAGE_GENERATION_METHOD') == 2 || (!Configuration::get('PS_IMAGE_GENERATION_METHOD') && $width_diff > $height_diff))

 

to:

if (Configuration::get('PS_IMAGE_GENERATION_METHOD') == 2 || (!Configuration::get('PS_IMAGE_GENERATION_METHOD') && $width_diff < $height_diff))

 

works on 1.5.2

 

+10 ^_^

  • Like 1
Link to comment
Share on other sites

  • 6 months later...
  • 2 months later...
  • 3 weeks later...
  • 3 months later...

This is awesome!:) It's such a great solution and really simple to do. Thanks adhd_kid!:):):)

For those people out there that were struggling like me, wondering why it didn't work at first, it's probably as simple as deleting the cashe/class_index.php file.

Link to comment
Share on other sites

  • 5 months later...

@martinf you see this should not be a big task: the zoom-crop code is taken directly from Timthumb and all current versions of that script contain a number of ways you can crop the image (crop to left, right, bottom, top), so the only thing to do would be to paste the missing code and create additional conditions somewhere after the _btt suffix such as "_btt_l" (for zoop-crop left) or "_btt_r" for zoom-crop right :-)

Link to comment
Share on other sites

Hi, 

 

I've replaced the code from classes/ImageManager.php and It doesn't work form me.. When I try to regenerate images, there is a fatal error 

 

Fatal error: Class 'ImageManagerCore' not found in /usr/home/../../classes/ImageManager.php on line 18

 

I'm using 1.5.6.2 version.

Could somebody help me?

 

Thanks!
 

Edited by dromansab (see edit history)
Link to comment
Share on other sites

@dromansab are you sure you put the code into /overrides/classes/ImageManager.php ? If you replaced the /classes/ImageManager.php then you need to bring it back ;) After you've done everything be sure to delete this file: /cache/class_index.php to make Prestashop aware of the changes.

Link to comment
Share on other sites

  • 3 weeks later...

 Saved my day!

 

Or...

in ImageManager.php

repleace:

if (Configuration::get('PS_IMAGE_GENERATION_METHOD') == 2 || (!Configuration::get('PS_IMAGE_GENERATION_METHOD') && $width_diff > $height_diff))
to:
if (Configuration::get('PS_IMAGE_GENERATION_METHOD') == 2 || (!Configuration::get('PS_IMAGE_GENERATION_METHOD') && $width_diff < $height_diff))
works on 1.5.2

 

 

Thanks! That works on 1.6 to.

  • Like 1
Link to comment
Share on other sites

  • 4 months later...

Hello,

 

It works for Prestashop 1.6.0.9, But I've got an error when I go to the product list in the BO.

Unknow error à la ligne 152 du fichier /home/www/override/classes/ImageManager.php
[2048] Declaration of ImageManager::resize() should be compatible with ImageManagerCore::resize($src_file, $dst_file, $dst_width = NULL, $dst_height = NULL, $file_type = 'jpg', $force_type = false, &$error = 0)

Do you know what could be the issue ? Thanks

Link to comment
Share on other sites

  • 3 weeks later...
  • 1 month later...
  • 6 months later...
  • 1 month later...

This all works great it 1.6.1.1

 

What I need now is an additional image resize method for thickbox images whereby prestashop does not resize images below the set image size. ie it doesn't add the white border if the image is smaller, it just leaves it, but does resize images that are larger. How can I do that?

Link to comment
Share on other sites

  • 1 month later...

Hello,

 

It works for Prestashop 1.6.0.9, But I've got an error when I go to the product list in the BO.

Unknow error à la ligne 152 du fichier /home/www/override/classes/ImageManager.php
[2048] Declaration of ImageManager::resize() should be compatible with ImageManagerCore::resize($src_file, $dst_file, $dst_width = NULL, $dst_height = NULL, $file_type = 'jpg', $force_type = false, &$error = 0)

Do you know what could be the issue ? Thanks

 

Having the same issue - the error only shows though if I hhave developer mode set to true - any solutions??  The image resize all works fine, just get theis error in dev mode

 

EDIT:

 

Solved this issue (in 1.6.1.1) by changing the first line of the override to:

public static function resize($src_file, $dst_file, $dst_width = null, $dst_height = null, $file_type = 'jpg',
                              $force_type = false, &$error = 0, &$tgt_width = null, &$tgt_height = null, $quality = 5,
                              &$src_width = null, &$src_height = null)
Edited by babyewok (see edit history)
Link to comment
Share on other sites

  • 5 months later...

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...