I am using the following script (source for iframe) to convert text to an image. <?php $Name = $_GET["Name"]; $ProjectID = $_GET["ProjectID"]; $Value = $_GET["Value"]; switch ($Name ) { case "TextSize": $Size = $Value; break; case "Shadow": $Shadow = $Value; break; case "TextEntry": $Text = $Value; break; case "Counter": $Counter = $Value; $file = "Images/Preview_Text/".$ProjectID.$Counter.".png"; break; } $image = imagecreatetruecolor(428, 100); $red = imagecolorallocate($image, 255, 0, 0); $black = imagecolorallocate($image, 0, 0, 0); $transparent = imagecolorallocate($image, 255, 255, 255); imagecolortransparent($image, $transparent); imagefilledrectangle($image, 0, 0, 428, 100, $transparent); $font = 'Fonts/grilcb__.ttf'; if ($Shadow == "yes") { imagettftext($image, $Size, 0, 24, 68, $black, $font, $text); } imagettftext($image, $Size, 0, 20, 64, $red, $font, $text); @imagepng($image,$file); echo "<html>"; echo "<head>"; echo "</head>"; echo "<body>"; echo "<img src='".$file."'>"; echo "</body>"; echo "</html>"; ?> Code (markup): All I get in return is this: ‰PNG IHDR¬dUf“–tRNSÿÿÿ7X}bIDAT8ÂÃÔ1 À0À¿ç!cG½zgæT½Ã€M&¤™ Âf‚@Å¡ i&¤™ Âf‚@Å¡ i&¤™ Âf‚@Å¡ i&¤™ Âf‚@Å¡ i&¤™ Âf‚@Å¡ i&¤™ Âf‚@Å¡ i&¤™ Âf‚@Å¡ i&¤™ Âf‚@Å¡ i&¤™ Âf‚@Å¡ i&¤™ Âf‚@Å¡ i&¤™ Âf‚@Å¡ i&¤™ Âf‚@Å¡ i&¤™ Âf‚@Å¡ i&¤™ Âf‚@Å¡ i&¤™ Âf‚@Å¡ i&¤™ Âf‚@Å¡ i&¤™ Âf‚@Å¡ i&¤™ Âf‚@Å¡ i&¤™ Âf‚@Å¡ i&¤™ Âf‚@Å¡ i&¤™ Âf‚@Å¡ i&¤™ Âf‚@Å¡ i&¤™ Âf‚@Å¡ i&¤™ Âf‚@Å¡ i&¤™ Âö`ìÅbäyªIEND®B`‚ It is possible I suppose that I am doing something wrong, would anyone care to hammer me over the head with what it is?
You should set the response's contentType to "/image/gif" or whatever is your image type is. The contentType should be changed before any response is written.
If you look at your switch, you'll notice that the $file variable is defined under case "Counter". This means that anytime $_GET['Name'] isn't set to "Counter" the $file variable will not be set. If the $file variable is null, imagePNG will output the contents of the PNG file to the browser (which is what is happening) instead of the file location you're attempting to specify. I'd imagine if you remove the @ from your imagePNG call you might get an error like: "Notice: Undefined variable: file in blah blah blah"