I have a transparent logo in a png file. I'm trying to create a transparent box image which would be the background for the logo. So the final image would be a merge of the programmatically-created, transparent png and the transparent logo from the file. The code that I'm using works, however the results show the logo with fuzzy black edges. Any ideas on how to get a sharper image?
Here is my code:
$source=imagecreatefrompng($logoFile);
imagealphablending($source, false);
imagesavealpha($source, true);
$newImage = imagecreatetruecolor(450,280);
$black = imagecolorallocate($newImage, 0, 0, 0);
imagecolortransparent($newImage, $black);
imagecopyresampled($newImage,$source,0,0,$x,$y,450,280,$width,$height);
imagepng($newImage,$imageDirectory,0);
imagedestroy($newImage);
Edited
Sorry, I guess I should've been more clear. The image file that is coming in is from a file upload form field. And most of the files are organization logos. Some of the .png files include a transparency alpha channel(they're not completely transparent). The reason that I have to recreate it is because I'm also using cropper.js, which is a tool that lets you zoom in or crop the file being uploaded, and I need the final file to be 450x280 regardless of how big or small the file uploaded was. So in my code, $x, $y, $width, $height
are sent by cropper.js after the user has manipulated the original image.
As I said, the image manipulation is working correctly. The only problem is that when I user submits a png with transparency, the logo is real fuzzy, with black edges. When I change black to another color in $black = imagecolorallocate($newImage, 0, 0, 0);
I loose all of the transparency.
Here is a sample input and output file. The one on the left is the original image, the one on the right is the output. The output of this test image isn't as bad as real images. There's way more fuzziness on real images.