support

Author Topic: Thumbnails white background padding  (Read 4155 times)

Offline otterslide

  • Newbie
  • *
  • Posts: 17
  • Karma: +3/-0
    • View Profile
Thumbnails white background padding
« on: December 04, 2014, 05:02:08 PM »
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!

Offline otterslide

  • Newbie
  • *
  • Posts: 17
  • Karma: +3/-0
    • View Profile
Re: Thumbnails white background padding
« Reply #1 on: December 05, 2014, 07:26:18 PM »
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

Code: [Select]
//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;
    }


 

Powered by SMFPacks Social Login Mod