Jump to content

How do I keep the transparency in resized gifs? < RESOLVED >


killerb

Recommended Posts

. . . and why can't i find anything about it already!!?

I have this process:

[code]<?php
move_uploaded_file($_FILES[$name]['tmp_name'],$dest);
$image_p = imagecreatetruecolor($tile_oblique_width, $h);
$image = imagecreatefromgif($dest);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $tile_oblique_width, $h, $dims['0'], $dims['1']);
$image = imagegif($image_p,$dest);

?>
[/code]

Problem is that I get a nasty black background where it should be transparent.

If I just move_uploaded_file without resizing, it is transparent as I want.

Is there actually a way to do this? - There must be!

Cheers.
Link to comment
Share on other sites

[code]
<?php
// The file
$filename = 'test.jpg';
$percent = 0.5;

// Content type
header('Content-type: image/jpeg');

// Get new dimensions
list($width, $height) = getimagesize($filename);
$new_width = $width * $percent;
$new_height = $height * $percent;

// Resample
$image_p = imagecreatetruecolor($new_width, $new_height);
$image = imagecreatefromjpeg($filename);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);

// Output
imagejpeg($image_p, null, 100);
?>
[/code]
Link to comment
Share on other sites

[quote="manual"]The transparent color is a property of the image, transparency is not a property of the color.[/quote]

You need to set it for the new image

[code]<?php
$ct = imagecolorat($image_p, 0,0);
imagecolortransparent($image_p, $ct);
imagegif($image_p, $dest);

imagedestroy($image_p);  // don't forget these lines
imagedestroy($image);
?>[/code]
Link to comment
Share on other sites

Well, yeah, jpeg is working fine, of course it doesn't give me transparency.

Adding imagecolortransparent works for .png, but not for gif. As well, the png is aliased to black matt. It is pretty clear that this is a realm of PHP I need to study, so I will do that sometime soon.

For the meantime, I must get on with it. This project is getting bigger and bigger by the day.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.