krodelabestiole Posted March 16, 2011 Share Posted March 16, 2011 i think adding this plain background to images is a really bad idea...to say it simply it makes image files heavier and it's uglyso i've just modified a bit images.inc.php so that it manage adaptive resize to thumbnails using php thumbas there :http://github.com/masterexploder/PHPThumb/wiki/Basic-Usage(scare thumbnails are filled with the photography, no dead spaces)so you have to download phpthumb and place it in a folder [prestashop root]/phpthumb/ you createthen edit [prestashop root]/images.inc.phpreplace (comment) imageResize function with this one function imageResize($sourceFile, $destFile, $destWidth = NULL, $destHeight = NULL, $fileType = 'jpg') { list($sourceWidth, $sourceHeight, $type, $attr) = getimagesize($sourceFile); if (!$sourceWidth) return false; if ($destWidth == NULL) $destWidth = $sourceWidth; if ($destHeight == NULL) $destHeight = $sourceHeight; require_once '../phpthumb/ThumbLib.inc.php'; $thumb = PhpThumbFactory::create($sourceFile); if ($destWidth > 300 || $destHeight > 300) { // if not a thumbnail then not square $thumb->resize($destWidth, $destHeight); } else { $thumb->adaptiveResize($destWidth, $destHeight); } return $thumb->save($destFile); } here you are !might be a bit dirty quick job : if the original picture is less than 300px high or wide then the main picture in front will be square cropped ...is there another way to know if the image is a thumnail or a full picture ?any else it should work fine 1 Link to comment Share on other sites More sharing options...
krodelabestiole Posted March 21, 2011 Author Share Posted March 21, 2011 hii mostly agreesure the more options you have the best it is (when you can hide these options to keep it simpler to users)the point is i install and cusomize this interface for clients or friends who rarely know how to use photoshop, compress jpeg and so on... not all pay professionnal photographers / webmasters at this endi guess on this purpose automation stays the best solution, and it should be much better managed than it is now with these ugly bordersphpthumb seems to me a nicer way to do this but i still miss some arguments in the fonction call to be the best.especially : are the size arguments strict or max (an info we would have to specify in the image settings for each small, medium, large, thickbox...)i hope some prestashop [spam-filter] will read about this Link to comment Share on other sites More sharing options...
krodelabestiole Posted March 21, 2011 Author Share Posted March 21, 2011 yep sure i saw thatfirst post is a workaround to this problemand it works quite fine : images up to 300px (usually thumbs) are both resized and cropped (adaptive resize) so that they fit exactly to their space, keeping aspect ratio.greater images (large pictures and thickboxes) are just uniformly resized to the max width OR max height specified in back officetherefore the remaining issue with this mod is that when you upload an image smaller than 300px (of course you can adjust that number in the code) it will have to fit exactly in both width and heigth, what may crop it a bit, even on full views.the best way to deal with that would be to implement phpthumb in ps next versionsand to add this strict/max option for each format in backoffice (i haven't mod this as it would ask to modify many other files and a bit of the database structure) Link to comment Share on other sites More sharing options...
krodelabestiole Posted March 21, 2011 Author Share Posted March 21, 2011 Quote first post is a workaround to this problem other good news is that it also works with gif and png, KEEPING TRANSPARENCIES :] Link to comment Share on other sites More sharing options...
krodelabestiole Posted March 24, 2011 Author Share Posted March 24, 2011 more likely this kind of scriptshttp://www.hotscripts.com/blog/javascript-image-cropping-scripts/http://deepliquid.com/projects/Jcrop/demos.php?demo=thumbnailseems to me it means a lot of work to implement Link to comment Share on other sites More sharing options...
tairlanz Posted May 2, 2011 Share Posted May 2, 2011 @krodelabestioleYOU ARE MY GOD AND SAVED MY LIFE.Thanks for this thread !!! I was stuck on thumbnails for 3 days !!!! Link to comment Share on other sites More sharing options...
User1234567891 Posted July 22, 2011 Share Posted July 22, 2011 I am not very strong in php. I tried several things, but I think I am replacing the wrong bit of code. In images.inc.php do i replace all this (line 138 to 182) function imageResize($sourceFile, $destFile, $destWidth = NULL, $destHeight = NULL, $fileType = 'jpg') { list($sourceWidth, $sourceHeight, $type, $attr) = getimagesize($sourceFile); if (!$sourceWidth) return false; if ($destWidth == NULL) $destWidth = $sourceWidth; if ($destHeight == NULL) $destHeight = $sourceHeight; $sourceImage = createSrcImage($type, $sourceFile); $widthDiff = $destWidth / $sourceWidth; $heightDiff = $destHeight / $sourceHeight; if ($widthDiff > 1 AND $heightDiff > 1) { $nextWidth = $sourceWidth; $nextHeight = $sourceHeight; } else { if (intval(Configuration::get('PS_IMAGE_GENERATION_METHOD')) == 2 OR (intval(Configuration::get('PS_IMAGE_GENERATION_METHOD')) == 0 AND $widthDiff > $heightDiff)) { $nextHeight = $destHeight; $nextWidth = intval(($sourceWidth * $nextHeight) / $sourceHeight); $destWidth = (intval(Configuration::get('PS_IMAGE_GENERATION_METHOD')) == 0 ? $destWidth : $nextWidth); } else { $nextWidth = $destWidth; $nextHeight = intval($sourceHeight * $destWidth / $sourceWidth); $destHeight = (intval(Configuration::get('PS_IMAGE_GENERATION_METHOD')) == 0 ? $destHeight : $nextHeight); } } $borderWidth = intval(($destWidth - $nextWidth) / 2); $borderHeight = intval(($destHeight - $nextHeight) / 2); $destImage = imagecreatetruecolor($destWidth, $destHeight); $white = imagecolorallocate($destImage, 255, 255, 255); imagefill($destImage, 0, 0, $white); imagecopyresampled($destImage, $sourceImage, $borderWidth, $borderHeight, 0, 0, $nextWidth, $nextHeight, $sourceWidth, $sourceHeight); imagecolortransparent($destImage, $white); return (returnDestImage($fileType, $destImage, $destFile)); With this: function imageResize($sourceFile, $destFile, $destWidth = NULL, $destHeight = NULL, $fileType = 'jpg') { list($sourceWidth, $sourceHeight, $type, $attr) = getimagesize($sourceFile); if (!$sourceWidth) return false; if ($destWidth == NULL) $destWidth = $sourceWidth; if ($destHeight == NULL) $destHeight = $sourceHeight; require_once '../phpthumb/ThumbLib.inc.php'; $thumb = PhpThumbFactory::create($sourceFile); if ($destWidth > 300 || $destHeight > 300) { // if not a thumbnail then not square $thumb->resize($destWidth, $destHeight); } else { $thumb->adaptiveResize($destWidth, $destHeight); } return $thumb->save($destFile);} Hope someone can give me little tip. Might be a good educational moment for me as well ;-)I am not sure how a function ends, that is why I am not sure which bit of code to replace. Thanks! Link to comment Share on other sites More sharing options...
User1234567891 Posted July 25, 2011 Share Posted July 25, 2011 Ok guys, just stumbled upon this after searching the forum for a couple of hours ;-) A very simple solution to get rid of these ugly white backgrounds. Just tested it, and works like a charm. This is the topic I got the solution from (hooray for TS Antuan of course!) TRICK - Crop images inside preserve ratio (no white spaces arround image) Here is how it works: Open images.inc.php In the following line (around 154) you should change > to < 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)) Had to share this find with you all! 1 Link to comment Share on other sites More sharing options...
justinl Posted October 18, 2011 Share Posted October 18, 2011 I wanted to confirm for people that this works in 1.4.4.1 Link to comment Share on other sites More sharing options...
krodelabestiole Posted October 18, 2011 Author Share Posted October 18, 2011 On 7/22/2011 at 6:19 PM, lostrisq said: I am not very strong in php. I tried several things, but I think I am replacing the wrong bit of code. In images.inc.php do i replace all this (line 138 to 182) With this: Hope someone can give me little tip. Might be a good educational moment for me as well ;-)I am not sure how a function ends, that is why I am not sure which bit of code to replace. You have to replace this : function imageResize($sourceFile, $destFile, $destWidth = NULL, $destHeight = NULL, $fileType = 'jpg') { list($sourceWidth, $sourceHeight, $type, $attr) = getimagesize($sourceFile); if (!$sourceWidth) return false; if ($destWidth == NULL) $destWidth = $sourceWidth; if ($destHeight == NULL) $destHeight = $sourceHeight; $sourceImage = createSrcImage($type, $sourceFile); $widthDiff = $destWidth / $sourceWidth; $heightDiff = $destHeight / $sourceHeight; if ($widthDiff > 1 AND $heightDiff > 1) { $nextWidth = $sourceWidth; $nextHeight = $sourceHeight; } else { if (intval(Configuration::get('PS_IMAGE_GENERATION_METHOD')) == 2 OR (intval(Configuration::get('PS_IMAGE_GENERATION_METHOD')) == 0 AND $widthDiff > $heightDiff)) { $nextHeight = $destHeight; $nextWidth = intval(($sourceWidth * $nextHeight) / $sourceHeight); $destWidth = (intval(Configuration::get('PS_IMAGE_GENERATION_METHOD')) == 0 ? $destWidth : $nextWidth); } else { $nextWidth = $destWidth; $nextHeight = intval($sourceHeight * $destWidth / $sourceWidth); $destHeight = (intval(Configuration::get('PS_IMAGE_GENERATION_METHOD')) == 0 ? $destHeight : $nextHeight); } } $borderWidth = intval(($destWidth - $nextWidth) / 2); $borderHeight = intval(($destHeight - $nextHeight) / 2); $destImage = imagecreatetruecolor($destWidth, $destHeight); $white = imagecolorallocate($destImage, 255, 255, 255); imagefill($destImage, 0, 0, $white); imagecopyresampled($destImage, $sourceImage, $borderWidth, $borderHeight, 0, 0, $nextWidth, $nextHeight, $sourceWidth, $sourceHeight); imagecolortransparent($destImage, $white); return (returnDestImage($fileType, $destImage, $destFile)); } which stand from line 116 to line 161 on my version of prestashop with this : function imageResize($sourceFile, $destFile, $destWidth = NULL, $destHeight = NULL, $fileType = 'jpg') { list($sourceWidth, $sourceHeight, $type, $attr) = getimagesize($sourceFile); if (!$sourceWidth) return false; if ($destWidth == NULL) $destWidth = $sourceWidth; if ($destHeight == NULL) $destHeight = $sourceHeight; require_once '../phpthumb/ThumbLib.inc.php'; $thumb = PhpThumbFactory::create($sourceFile); if ($destWidth > 300 || $destHeight > 300) { // if not a thumbnail then not square $thumb->resize($destWidth, $destHeight); } else { $thumb->adaptiveResize($destWidth, $destHeight); } return $thumb->save($destFile); } You can as well comment the first code by adding /* at first and */ after the end of the function then paste the second code underneath. I don't know why this whole code is on the same line on your quote : // if not a thumbnail then not square $thumb->resize($destWidth, $destHeight); } else { $thumb->adaptiveResize($destWidth, $destHeight); } return $thumb->save($destFile);} but it won't work this way cause everything is commented (// means the next code on the line won't be executed in PHP) Link to comment Share on other sites More sharing options...
Jamfris Posted May 18, 2012 Share Posted May 18, 2012 It worked like a charm in 1.4.7 what lotrisq wrote. It would be nice to avoid cropping on the thumb of the related products. But I think it's completely bearable Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now