0
votes

I am trying to make image generator php file and I use this code>

<?php
header('content-type: image/jpeg');
$email = '[email protected]';
$email_length = strlen($email);
$font_size = 4;
$image_height = imagefontheight($font_size);
$image_width = imagefontheight($font_size) * $email_length;
$image = imagecreate($image_width, $image_height);
imagecolorallocate($image, 255, 255, 255);
$font_color = imagecolorallocate($image, 0, 0, 0);
imagestring($image, $font_size, 0, 0, $email, $font_color);
imagejpeg($image);
?>

and it shows no image when I load the file in Chrome. In Mozilla it shows error 'The image "..." cannot be displayed because it contains errors'. But when I put imagejpeg($image,"new.jpg"); instead of imagejpeg($image); it makes the img file correctly. Does anyone know what should I do to fix this problem?

1
It's probably a PHP parse error that it's displaying because you've set the content type to be an image. I've run this locally and it seems to work fine, I'd suggest you comment out the header call and run the script directly to see if there's any PHP errors coming out. - scrowler
I tried that and it shows no error, but raw data in the browser. - sJefremov

1 Answers

0
votes

I put your code on my local web server, took out the header call, and I got an error saying that the function imagefontheight is undefined.

I'm thinking you may not have the GD library installed, so a call to any image... function fails.

I can't tell you any more, unless you tell us what operating system you have, and how PHP is being ran. (CLI, in Apache, etc.)