I am trying to get transparency for working with my application (which dynamically resizes images before saving them), and I think that I finally narrowed down the problem after many wrong directions to imagealphablending and imagesavealpha . The original image never loads with proper transparency!
// With this line, the output image has no transparency (where it should be // transparent, colors bleed out randomly or it completely black, depending // on the image) $img = imagecreatefromstring($fileData); // With this line, it works as expected. $img = imagecreatefrompng($fileName); // Blah blah blah, lots of image resize code into $img2 goes here; I finally // tried just outputting $img instead. header('Content-Type: image/png'); imagealphablending($img, FALSE); imagesavealpha($img, TRUE); imagepng($img); imagedestroy($img);
It would be a serious architectural difficulty to load an image from a file; this code is used with the JSON API that is requested from the iPhone application, and in this case (and more consistent) it is easier to load base64 encoded images in POST data. Do I really need to somehow save the image as a file (just so that PHP can load it into memory again)? Is it possible to create a Stream from $fileData , which can be passed to imagecreatefrompng ?
meustrus
source share