, I ...">

GD library not working

The generate.php file works, however, if I try to get an image in my index.php using <img src="generate.php"/>

, I get a blank screen.

generate.php

<?php
    header('Content-type: image/png');

    if(isset($_GET['email'])){
        $email = $_GET['email'];
    }else{
        $email = 'No email specified';
    }
    $email_length = strlen($email);

    $font_size = 4;

    $image_height = ImageFontHeight($font_size);
    $image_width = ImageFontWidth($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);
    imagepng($image);
?>

      

index.php

Name:<br>
Dave
<br><br>
Email: <br>
<img src="generate.php"/>

      

+3


source to share


1 answer


It could be a coding error that corrupted the image header.



Make sure your generate.php file is saved as UTF-8 without BOM or ASCII.

-1


source







All Articles