I have a simple service that generates a PNG image of any text, using the parameters passed via a URL. One of the parameters is the text itself, the rest are things like 'font', 'color', 'font weight' etc.
An example of such a URL is: http://picselbocs.com/projects/cakemyface/text.php?params=Verdana%7C18%7Cbold%7Cnormal%7Ccenter%7C%23cc0000%7Cunderline&text=Hello%20world!
which generates the following PNG:
In another script, I'm using cURL to retrieve such a resource generated by this service, which I then convert to an image using imagecreatefromstring()
, because I need to operate on it - things like rotating and scaling -, then to merge it with some other images.
For this I use the following code:
function getImage($url){
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
$resource = curl_exec($ch);
curl_close ($ch);
return $resource;
}
$url = "http://picselbocs.com/projects/cakemyface/text.php?params=Verdana%7C18%7Cbold%7Cnormal%7Ccenter%7C%23cc0000%7Cunderline&text=Hello%20world!";
$string = getImage($url);
$image = imagecreatefromstring($string);
// Send the image to the client
header("Content-type: image/png");
header("Content-disposition: inline; filename=mytext.png");
imagepng($image);
imagedestroy($image);
This same code is available here, where you can see the output. The problem is that the code above outputs some strange PNG, where all the letters are filled rectangles, like in the example bellow:
Why does this happen and how can I solve it?
One other curious thing is that if I replace a URL to a text-image with, for instance, a link to a QR code generated with the Google Charts tool (e.g. QR code), the result is what it's supposed to be...