Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Echo missing after generating image

Tags:

php

$data = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl'
      . 'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr'
      . 'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r'
      . '8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg==';
$data = base64_decode($data);

$im = imagecreatefromstring($data);
if ($im !== false) {

    header("Cache-Control: no-cache, must-revalidate");
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    header('Content-Type: image/png');
    imagepng($im);

    //echo '<a href=\'imagepng('.$im.')\'> Download </a>';
    echo "-----------------";

} else {
    echo 'An error occurred.';
}

It shows the image but does not echo "==============".

like image 507
Shaun Avatar asked Sep 04 '26 16:09

Shaun


2 Answers

You told the browser to expect an image, therefore it's only expecting an image. Everything sent will be considered part of the data for that image. And no, it won't convert text you send into part of the image.

like image 76
Ignacio Vazquez-Abrams Avatar answered Sep 07 '26 07:09

Ignacio Vazquez-Abrams


This is because of your

header('Content-Type: image/png');

It prevents you from echoing something else than the picture on this page. (Well it doens't, but your Browser thinks this still part of the picture)

If you want to echo picture and Text, you need a seperat file, e.g. like this

echo '<img source="./pic.php" alt="pic" height="20" width="20" />';
echo '______________';

wehere pic.php is the path to the file wich echos the picture.

like image 41
Tokk Avatar answered Sep 07 '26 05:09

Tokk



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!