Jump to content


Photo

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


  • Please log in to reply
5 replies to this topic

#1 killerb

killerb
  • Members
  • PipPipPip
  • Advanced Member
  • 48 posts

Posted 13 August 2006 - 04:05 AM

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

I have this process:

<?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);

?>

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.
Experience is something you get just after you need it.

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 13 August 2006 - 04:19 AM

<?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);
?> 

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 13 August 2006 - 09:57 AM

The transparent color is a property of the image, transparency is not a property of the color.


You need to set it for the new image

<?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);
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#4 killerb

killerb
  • Members
  • PipPipPip
  • Advanced Member
  • 48 posts

Posted 13 August 2006 - 12:48 PM

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.
Experience is something you get just after you need it.

#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,017 posts

Posted 13 August 2006 - 12:55 PM

If creating gif or png, try imagecreate instead of imagecreatetruecolor
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#6 killerb

killerb
  • Members
  • PipPipPip
  • Advanced Member
  • 48 posts

Posted 13 August 2006 - 02:11 PM

Yay its working!  Cheers Mate!

Experience is something you get just after you need it.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users