Page 1 of 1

php png

Posted: Fri Oct 17, 2003 3:29 pm
by ThinkGeekness
Hi, I have a php script that generates the email addresses in png format. The only problem is, is that it is not working.. Can anybody tell me what I did wrong? Also, I am using the default apache and php installation that comes with Red Hat (rpm).

Code: Select all

<?
Header("Content-type: image/png");
$s = 9;
$text = "ERROR";
$uname = "";
$sname = "";
$link = 0;
if(isset($_GET&#1111;"u"])) $uname = $_GET&#1111;"u"];
if(isset($_GET&#1111;"s"])) $sname = $_GET&#1111;"s"];
if(isset($_GET&#1111;"l"])) $link = $_GET&#1111;"l"];
$text = "$uname@$sname";
$font = "/home/webadmin/public_html/verdana.ttf";
$size = imagettfbbox($s, 0, $font, $text);
$dx = abs($size&#1111;2]-$size&#1111;0]);
$dy = abs($size&#1111;5]-$size&#1111;3]);
$pad = 3;
$w = $dx+$pad*2;
$h = $dy+$pad*2;
$im = imagecreate($w, $h);
$fg = $bg = 0;
switch($link) &#123;
	case 0: $fg=ImageColorAllocate($im, 0, 0, 0); break;
	case 1: $fg=ImageColorAllocate($im, 0xC0, 0, 0); break;
	case 2: $fg=ImageColorAllocate($im, 0xFF, 0xFF, 0xFF); break;
&#125;
switch($link) &#123;
	case 0: case 1: $bg=ImageColorAllocate($im, 0xFF, 0xFF, 0xFF); break;
	case 2: $bg=ImageColorAllocate($im, 0x0, 0x0, 0x0); break;
&#125;
ImageFilledRectangle($im, 0, 0, $w, $h, $bg);
ImageTTFText($im, $s, 0, $pad, $h-$pad, $fg, $font, $text);
ImagePng($im);
ImageDestroy($im);
?>
The image shows up as a broken image is what outputs.

Thanks!

Posted: Fri Oct 17, 2003 3:40 pm
by ThinkGeekness
toweter wrote:which browser do you use?
you can look the errors at the sourcecode of the image by viewing file...
ie, mozilla, firebird, netscape, all the same thing.

For the source, all it says is:
<img src='/email.php?u=email&s=domain.com&l=2'>

Posted: Fri Oct 17, 2003 3:53 pm
by volka
try

Code: Select all

<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
$s = 9;
$text = "ERROR";
$uname = "";
$sname = "";
$link = 0;
if(isset($_GET["u"])) $uname = $_GET["u"];
if(isset($_GET["s"])) $sname = $_GET["s"];
if(isset($_GET["l"])) $link = $_GET["l"];
$text = "$uname@$sname";
$font = "/home/webadmin/public_html/verdana.ttf";
$size = imagettfbbox($s, 0, $font, $text);
$dx = abs($size[2]-$size[0]);
$dy = abs($size[5]-$size[3]);
$pad = 3;
$w = $dx+$pad*2;
$h = $dy+$pad*2;
$im = imagecreate($w, $h);
$fg = $bg = 0;
switch($link) {
   case 0: $fg=ImageColorAllocate($im, 0, 0, 0); break;
   case 1: $fg=ImageColorAllocate($im, 0xC0, 0, 0); break;
   case 2: $fg=ImageColorAllocate($im, 0xFF, 0xFF, 0xFF); break;
}
switch($link) {
   case 0: case 1: $bg=ImageColorAllocate($im, 0xFF, 0xFF, 0xFF); break;
   case 2: $bg=ImageColorAllocate($im, 0x0, 0x0, 0x0); break;
}
ImageFilledRectangle($im, 0, 0, $w, $h, $bg);
ImageTTFText($im, $s, 0, $pad, $h-$pad, $fg, $font, $text);
if (!headers_sent())
{
   Header("Content-type: image/png");
   ImagePng($im);
}
ImageDestroy($im);
?>
and call the document directly (so the browser can handle the mime-type). It should display any error that occurs

Posted: Fri Oct 17, 2003 3:55 pm
by ThinkGeekness
toweter wrote:you must look at the sourcecode of the image, not of the htmlpage.
there must be (by using mozilla firebird) one or more lines with errors and then the image-code (unreadable...)
Thanks, I figured it out (with your help with the image-code in firebird).. I didnt have the font in that location. Thanks!