Virtuemart Resize GIF Black Background Issue
If you have VirtualMart 1.1 with Joomla 1.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.
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.


0 Comments:
Post a Comment
<< Home