Welcome Guest, Not a member yet? Register   Sign In
Preserving transparency when creating thumbnails
#2

[eluser]InsiteFX[/eluser]
Hi,

Here is a work around, the problem is in the GD2 library.

Code:
$image = imagecreatefromjpeg('booh.jpg');
list($image_width, $image_height) = getimagesize('booh.jpg');
$water = imagecreatefrompng('text.png');
list($water_width, $water_height) = getimagesize('text.png');

$water_resized_width = $water_width * 0.5;
$water_resized_height = $water_height * 0.5;

$resized = imagecreatetruecolortransparent($water_resized_width, $water_resized_height);
imagecopyresampled($resized, $water, 0, 0, 0, 0, $water_resized_width, $water_resized_height, $water_width, $water_height);

imagecopy($image, $resized, (($image_width - $water_resized_width) / 2), (($image_height - $water_resized_height) / 2), 0, 0, $water_resized_width, $water_resized_height, 15);
imagejpeg($image, 'finished.jpg', 100);
imagedestroy($image);
imagedestroy($water);
imagedestroy($resized);

function imagecreatetruecolortransparent($x, $y)
{
$i = imagecreatetruecolor($x, $y);
$b = imagecreatefromstring(base64_decode(blankpng()));
imagealphablending($i, false);
imagesavealpha($i, true);
imagecopyresized($i, $b ,0 ,0 ,0 ,0 ,$x, $y, imagesx($b), imagesy($b));
return $i;
}

function blankpng()
{
$c = "iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAABGdBTUEAAK/INwWK6QAAABl0RVh0U29m";
$c .= "dHdhcmUAQWRvYmUgSW1hZ2VSZWFkeXHJZTwAAADqSURBVHjaYvz//z/DYAYAAcTEMMgBQAANegcCBNCg";
$c .= "dyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAAN";
$c .= "egcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQ";
$c .= "oHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAADXoHAgTQoHcgQAANegcCBNCgdyBAAA16BwIE0KB3IEAA";
$c .= "DXoHAgTQoHcgQAANegcCBNCgdyBAgAEAMpcDTTQWJVEAAAAASUVORK5CYII=";
return $c;
}

It should also work with png, this is not tested by me.

Enjoy
InsiteFX


Messages In This Thread
Preserving transparency when creating thumbnails - by El Forum - 10-02-2009, 04:03 AM
Preserving transparency when creating thumbnails - by El Forum - 10-02-2009, 01:50 PM



Theme © iAndrew 2016 - Forum software by © MyBB