News:

Looking for documentation? Take a look on our wiki

Main Menu

Virtuemart Resize GIF Black Background Issue

Started by tobias_conrad, October 31, 2013, 16:24:37 PM

Previous topic - Next topic

tobias_conrad

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

#1
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


jenkinhill

The server GD library cannot handle transparent gifs or pngs.  Ideslly just use .jpg images.
Kelvyn
Lowestoft, Suffolk, UK

Retired from forum life November 2023

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