News:

AbanteCart v1.4.2 is released.

Main Menu

Do you like AbanteCart? Please rate AbanteCart or share your experience with other eCommerce entrepreneurs. Go to Softaculous rating page to add your rating or write a review

Thumbnails white background padding

Started by otterslide, December 04, 2014, 05:02:08 PM

Previous topic - Next topic

otterslide

Hello,

Is there a simple way to remove the white padding from my thumbnails?  I want to add box shadow to my item thumbnails, but the white padding that makes all photos same size is preventing this..

Any help is appreciated!  I can change php code if needed.

Thanks!

otterslide

I've figured it out, based on some code I found online.

If anyone ever needs this, here is the code.. I just change resize() function.

You'll need to maintain this across upgrades as it modified AbanteCart functionality directly.

core/lib/image.php


//new function I made
public function newResize($width, $height)
{

$THUMBNAIL_IMAGE_MAX_WIDTH = $width;
$THUMBNAIL_IMAGE_MAX_HEIGHT = $height;

$source_image_width = $this->info['width'] ;
$source_image_height = $this->info['height'];

$source_gd_image = $this->image;


$source_aspect_ratio = $source_image_width / $source_image_height;
$thumbnail_aspect_ratio = $THUMBNAIL_IMAGE_MAX_WIDTH / $THUMBNAIL_IMAGE_MAX_HEIGHT;
if ($source_image_width <= $THUMBNAIL_IMAGE_MAX_WIDTH && $source_image_height <= $THUMBNAIL_IMAGE_MAX_HEIGHT) {
$thumbnail_image_width = $source_image_width;
$thumbnail_image_height = $source_image_height;
} elseif ($thumbnail_aspect_ratio > $source_aspect_ratio) {
$thumbnail_image_width = (int) ($THUMBNAIL_IMAGE_MAX_HEIGHT * $source_aspect_ratio);
$thumbnail_image_height = $THUMBNAIL_IMAGE_MAX_HEIGHT;
} else {
$thumbnail_image_width = $THUMBNAIL_IMAGE_MAX_WIDTH;
$thumbnail_image_height = (int) ($THUMBNAIL_IMAGE_MAX_WIDTH / $source_aspect_ratio);
}
$this->image = imagecreatetruecolor($thumbnail_image_width, $thumbnail_image_height);

imagecopyresampled($this->image, $source_gd_image, 0, 0, 0, 0, $thumbnail_image_width, $thumbnail_image_height, $this->info['width'], $this->info['height']);


if(is_resource($source_gd_image)){
imagedestroy($source_gd_image);
}


$this->info['width']  = $thumbnail_image_width;
        $this->info['height'] = $thumbnail_image_height;

return true;
}


    public function resize($width = 0, $height = 0, $nofill=flase) {
   

if (!$this->info['width'] || !$this->info['height']) {
return;
}
        if ($width == 0 && $height == 0) {
return;
}

if(is_resource($this->image)){
$this->newResize($width, $height);
}
 
    return true;
    }


Forum Rules Code of conduct
AbanteCart.com 2010 -