Forum Moderators: coopster

Message Too Old, No Replies

Image transperancy detection!

How to do it?

         

smagdy

4:08 pm on Nov 30, 2006 (gmt 0)

10+ Year Member



Hello,

I was using a script to upload images and been working good for 6 months but then i discovered that uploaded images with transperancy turns to black!

SO i found out how to fix that using this function imagecolortransparent()

But then i found out that pictures with shadow created in photoshop get like strange pixels around the shadow!

SO i just want to detect if there is transperancy then i use that function, otherwise i dont use it!

The thing is that the images with shadow works fine if i dont use the imagecolortransparent() function!

Any input is appreciated!

Thanks in advance

swa66

9:56 pm on Nov 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



what image formats? gif, png?

smagdy

10:21 pm on Nov 30, 2006 (gmt 0)

10+ Year Member



gif

whoisgregg

11:05 pm on Nov 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



From the manual page on imagecolortransparent [php.net], you can call the function without setting the color and it will return the current transparent color. If no color is transparent it will return -1 (according to a comment, might actually be an empty string but testing can quickly determine this).

So, also basically from a comment on that manual page, here's the way to check if transparency exists:

$transparentcolor = imagecolortransparent($img_resource);
if($transparentcolor >= 0){
// image has transparency
}

smagdy

12:13 pm on Dec 1, 2006 (gmt 0)

10+ Year Member



Worked great... thanks

But it detects also jpg images! it gives -1

whoisgregg

3:45 pm on Dec 1, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Since JPEG doesn't support transparency it will always return -1 for a JPEG.