Reputation: 641
I have a strange problem with PHP Images and Webbrowsers..
First of all, I know that PHP is a server-side language and that it has nothing to do with the browser, but WHY THE HELL is my script working with Firefox or Safari or Chrome and not with Internet Explorer??
function image_effect_negative($counter,$file,$layer){
$image = "../images/tmp/$file/layer_$layer.png";
$img = imagecreatefrompng($image);
if($layer == 0){
$path = "../images/tmp/$file/$counter".".jpg";
}else{
$path = "../images/tmp/$file/layer_$layer.png";
$path2 = "../images/tmp/$file/tmp_layer_$layer.png";
}
if($img && imagefilter($img, IMG_FILTER_NEGATE)){
//imagepng($img, $path);
if($layer > 0)
imagepng($img, $path2);
else
imagejpeg($img,$path);
imagedestroy($img);
return $img;
}
}
I use the code above, that loads layer_0.png (for example) and uses an imagefilter on it. With every other browser the Image with the effect is created, but not in IE !
What is wrong??
Upvotes: 0
Views: 625
Reputation: 146500
My guess is that you aren't generating HTTP headers. Some browsers are able to detect whether http://example.com/foo.php
contains a PNG or JPEG files, other browsers are not. It's as simple as:
if($layer > 0){
header('Content-Type: image/png');
imagepng($img, $path2);
}
else{
header('Content-Type: image/jpeg');
imagejpeg($img,$path);
}
Upvotes: 0
Reputation: 11
What version of Internet Explorer are you using? Older versions of IE are known to not work with transparency types such as pngs. Try adding PNG fixer to your page for IE and see if that fixes it. You can find PNG fixer here:
http://jquery.andreaseberhard.de/pngFix/
Upvotes: 1
Reputation: 91742
What do you expect to return when you destroy the image before that?
imagedestroy($img); // why are you destroying the image?
return $img;
}
Also, have you set the correct header to return an image to the browser?
Upvotes: 0