Author Topic: Virtuemart Resize GIF Black Background Issue  (Read 2630 times)

tobias_conrad

  • Beginner
  • *
  • Posts: 44
    • Herbs and Spices may help you. Find it out.
Virtuemart Resize GIF Black Background Issue
« on: October 31, 2013, 16:24:37 pm »
Can you confirm and include a solution for this bug in the next version?
I uploaded category .gif pictures with transparent background and the background turned black.
VM2 file for thumb creation:
/administrator/components/com_virtuemart/helpers/img2thumb.php

Virtuemart Resize GIF Black Background Issue
If you have VirtualMart 2.0.22 with Joomla 2.5's default installation, you may find a problem when uploading a picture with GIF format and letting the system generate a thumbnail image - the background of the generated image will have a black background while the original image has a transparent background.

We don't want that of course. It seems like the code has a bug.

Here's a fix for this:

Use your favorite text editor and edit the following file:

your_virtuemart_installation/administrator/components/ com_virtuemart/classes/class.img2thumb.php

Approximately line 210, comment out the following code:

/*
// New modification - creates new image at maxSize
if( $this->maxSize )
{
if( function_exists("imagecreatetruecolor") )
$im_out = imagecreatetruecolor($maxX,$maxY);
else
$im_out = imagecreate($maxX,$maxY);

// Need to image fill just in case image is transparent, don't always want black background
$bgfill = imagecolorallocate( $im_out, $this->bg_red, $this->bg_green, $this->bg_blue );
//$bgfill = imagecolorallocate( $im_out, $this->bg_red, $this->bg_green, $this->bg_blue );
if( function_exists( "imageAntiAlias" )) {
imageAntiAlias($im_out,true);
}
imagealphablending($im_out, false);
if( function_exists( "imagesavealpha")) {
imagesavealpha($im_out,true);
}
if( function_exists( "imagecolorallocatealpha")) {
$transparent = imagecolorallocatealpha($im_out, 255, 255, 255, 127);
}

//imagefill( $im_out, 0,0, $bgfill );
if( function_exists("imagecopyresampled") ){
ImageCopyResampled($im_out, $orig_img, $adjustX, $adjustY, 0, 0, $newxsize, $newysize,$orig_size[0], $orig_size[1]);
}
else {
ImageCopyResized($im_out, $orig_img, $adjustX, $adjustY, 0, 0, $newxsize, $newysize,$orig_size[0], $orig_size[1]);
}

}
else
{

if( function_exists("imagecreatetruecolor") )
$im_out = ImageCreateTrueColor($newxsize,$newysize);
else
$im_out = imagecreate($newxsize,$newysize);

if( function_exists( "imageAntiAlias" ))
imageAntiAlias($im_out,true);
imagealphablending($im_out, false);
if( function_exists( "imagesavealpha"))
imagesavealpha($im_out,true);
if( function_exists( "imagecolorallocatealpha"))
$transparent = imagecolorallocatealpha($im_out, 255, 255, 255, 127);

if( function_exists("imagecopyresampled") )
ImageCopyResampled($im_out, $orig_img, 0, 0, 0, 0, $newxsize, $newysize,$orig_size[0], $orig_size[1]);
else
ImageCopyResized($im_out, $orig_img, 0, 0, 0, 0, $newxsize, $newysize,$orig_size[0], $orig_size[1]);
}


return $im_out;
}

*/

Add the following code instead:

if( $this->maxSize )
{
$im_out = ImageCreateTrueColor($maxX,$maxY);
$bgfill = imagecolorallocate( $im_out, $this->bg_red, $this->bg_green, $this->bg_blue );
imagefill( $im_out, 0,0, $bgfill );
ImageCopyResampled($im_out, $orig_img, $adjustX, $adjustY, 0, 0,
$newxsize, $newysize,$orig_size[0], $orig_size[1]);
}
// Need to image fill just in case image is transparent, don't always want black background
else
{
$im_out = ImageCreateTrueColor($newxsize,$newysize);
$bgfill = imagecolorallocate( $im_out, $this->bg_red, $this->bg_green, $this->bg_blue );
imagefill( $im_out, 0,0, $bgfill );
ImageCopyResampled($im_out, $orig_img, 0, 0, 0, 0,
$newxsize, $newysize,$orig_size[0], $orig_size[1]);
}
return $im_out;
}

The original code was trying to handle this issue but it just doesn't work. The later code seems to be working but we have not fully tested it yet so use at your own risk.

Here's the reference.


posted by Votech Blogger at 11:00 PM
Maybe the best set of extensions in a gorgeous template for less than 50$.
http://clicky.me/gorgeous-template

oO_Oo

  • Beginner
  • *
  • Posts: 3
  • A beginner
Re: Virtuemart Resize GIF Black Background Issue
« Reply #1 on: July 21, 2015, 09:21:25 am »
The problem is still exist in VM 3.0.9.4. If I resized my gif based category image (transparent background), I get black background.

zakgr

  • Beginner
  • *
  • Posts: 8
Re: Virtuemart Resize GIF Black Background Issue
« Reply #2 on: March 25, 2017, 23:02:37 pm »
I have the same problem with vm3.018

jenkinhill

  • UK Web Developer & Consultant
  • Global Moderator
  • Super Hero
  • *
  • Posts: 26421
  • Always on vacation
    • Jenkin Hill Internet
Re: Virtuemart Resize GIF Black Background Issue
« Reply #3 on: March 26, 2017, 00:19:19 am »
The server GD library cannot handle transparent gifs or pngs.  Ideslly just use .jpg images.
Kelvyn

Jenkin Hill Internet,
Lowestoft, Suffolk, UK

Unsolicited PMs/emails will be ignored.

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum

Currently using VM3.2.8 on Joomla 3.8.2 PHP 7.0.25

Testing VM3.2.8 on J3.8.3RC