-1

i've testing on localserver and online web server... but return a null image...

check return result... http://s8.postimage.org/sthztzj5x/null_image.jpg

<?php
Set the content-type
header('Content-Type: image/png');
$im = imagecreatetruecolor(400, 30);
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
$text = 'Testing...';
$font = 'arial.ttf';
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
imagepng($im);
imagedestroy($im);
?>
Rameez SOOMRO
  • 1,529
  • 15
  • 24
  • You aren't checking *any* of those return values. One of those functions is probably failing. Comment out the `header` call, add `error_reporting(-1); ini_set('display_errors', true);` and try again. I bet you'll see a big fat PHP error, warning or notice. – Charles Dec 16 '12 at 20:18
  • You need to enable error logging (logging is important because the image does not display text to you) in PHP. Set the reporting to the highest level. Then follow the error log, it tells you where the error is. See as well [how do i debug PHP Image with print?](http://stackoverflow.com/q/11900852/367456) and [PHP invalid image's and error handling](http://stackoverflow.com/q/2574713/367456) – hakre Dec 16 '12 at 20:18

2 Answers2

0

The second line of this script causes a PHP parse error. Add double slashes to the front of it like this:

// Set the content-type

Ray Paseur
  • 2,106
  • 2
  • 13
  • 18
0

This worked correctly for me.

http://www.laprbass.com/RAY_temp_rameez.php

<?php // RAY_temp_rameez.php
error_reporting(E_ALL);

// Set the content-type
header('Content-Type: image/png');
$im = imagecreatetruecolor(400, 30);
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
$text = 'Testing...';
$font = 'fonts/verdanaz.ttf';
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
imagepng($im);
imagedestroy($im);
Charles
  • 50,943
  • 13
  • 104
  • 142
Ray Paseur
  • 2,106
  • 2
  • 13
  • 18
  • 1
    This should be edited into your existing answer and/or one or the other should be deleted. – Charles Dec 16 '12 at 20:30
  • @Ray Paseur: I now see this a second time. Do you have a problem using the editing tools? If you don't give feedback nor cleanup the stuff, you might see some downvotes and flags. Take care. – hakre Dec 16 '12 at 21:10
  • @RayPaseur, you should post one answer that corrects all of the raised problems (and problems that exist and need to be fixed but that weren't brought up). There are rare cases where you might want to present two entirely (*philosophically*) different answers, and it's OK to post them separately. This isn't one of those. I think I've seen it done maybe a dozen times in the past year, and then only for *really good* questions. This ... this is a bad question. – Charles Dec 16 '12 at 21:31
  • Also, with respect as you seem to generally know what you're doing... you need to lurk more. SO has a very different way of operating and a vastly different culture than EE does, and you're going to need more time to pick up local customs. You might also want to skim through [the meta faq](http://meta.stackexchange.com/questions/tagged/faq). – Charles Dec 16 '12 at 21:36
  • @Charles: I went to the meta faq and set the display to 50 per page. And it gave me 3 pages of responses. I'd be grateful for a succinct summary of the cultural issues as you see them. I think I can make a contribution to the SO community, and if you can help me find the ways to do that, it would be great. Also, I'm not predisposed to assume that any question is a bad question. I'm human and I make mistakes, even in PHP, which I teach for Boston University. So please give me a hand, thanks. – Ray Paseur Dec 16 '12 at 22:14
  • @RayPaseur: All fine and dandy. Just merge the two answers here I'd say. And welcome to SO. Merge here, too: http://stackoverflow.com/a/13903776/367456 ; http://stackoverflow.com/a/13903464/367456 – hakre Dec 16 '12 at 22:26