coffeemonitor
coffeemonitor

Reputation: 13120

php imagecreatefrompng

I have an image I created in Macromedia (Adobe) Fireworks. I exported it as a PNG32, with a transparent background. It's fine when I call the image to the browser normally:

<img src="myimage.png" />

However, when I use php to display the image, I have aliasing problems. The edges of the image get pixelated. And for those who want to know what the image is, it's a cartoon face, with a border of about 2 pixels - outlining the character.

I've played around with my code, but the same thing happens.

Here's what I've coded:

<?php
$img = 'myimage.png';
$img = imagecreatefrompng($img);
header('Content-type: image/png');
imagepng($img);
imagedestroy($img);
?>

Without actually uploading a sample of the image, which I'll do if necessary, does someone understand why borders would get choppy?

Upvotes: 2

Views: 2456

Answers (1)

Stephane Gosselin
Stephane Gosselin

Reputation: 9148

I would try this to see if it helps:

<?php
$img = 'myimage.png';
$img = imagecreatefrompng($img);
// enables alpha channel
imagealphablending($img, true); // setting alpha blending on
imagesavealpha($img, true); // save alphablending setting (important)

Upvotes: 2

Related Questions