0

I'm trying to draw a simple image with GD on PHP 7.2.5 on my Server (Debian 4.9.88-1+deb9u1).

My source code looks simply like that:

<?php
    error_reporting(E_ALL);

    header("Content-type: image/png");
    $string = $_GET['text'];
    $im     = imagecreatefromjpeg("test.jpg");
    $orange = imagecolorallocate($im, 220, 210, 60);
    $px     = (imagesx($im) - 7.5 * strlen($string)) / 2;
    imagestring($im, 3, $px, 9, $string, $orange);
    imagepng($im);
    imagedestroy($im);

?>

test.jpg is available in the same folder. PHP-Version: 7.2.5
I can't see anything related in the log files.

GD is activated on the server:

enter image description here

Result looks like that:

Result of the previous shown source code

halfer
  • 19,824
  • 17
  • 99
  • 186
Ben S.
  • 1
  • 2
  • Your code works for me on PHP 7.1.18. Try it with a different JPG file. – timclutton Jun 01 '18 at 08:52
  • @timclutton I tried it now with a similar picture - no success. Could it be a right related issue? Or must it be a "JPEG" instead of "JPG"? – Ben S. Jun 01 '18 at 08:57
  • That would be my first guess. Try a simple one line script like: `var_dump(file_get_contents('test.jpg'));` and confirm your script reads data from the file. – timclutton Jun 01 '18 at 08:59
  • For my `image.jpg` it displays `bool(false)` but for another jpg a content is shown. But there's no change when I set 777 as rights. – Ben S. Jun 01 '18 at 09:03
  • nevermind... The output of `image.jpg` looks like: [link](https://imgur.com/a/ACN8EnP) – Ben S. Jun 01 '18 at 09:06
  • Ok, that's not a JPG. It looks like a PSD file, at a guess. – timclutton Jun 01 '18 at 09:08
  • Okay, but the pic from the internet also looks like that: [link](https://imgur.com/a/g4BvAul) – Ben S. Jun 01 '18 at 09:25
  • Ah, slightly different, but I guess that reference is the EXIF data about the package used to create the image. My mistake. So, it looks like you can read the file; now check if GD can load the image: `var_dump(imagecreatefromjpeg('test.jpg'));` It should return something like `resource(3, gd)`. – timclutton Jun 01 '18 at 09:30
  • `resource(3) of type (gd)` (btw. thanks for your effort!) – Ben S. Jun 01 '18 at 09:35
  • @timclutton I've tested it one more time. Everything works fine until this line is added: `header("Content-type: image/png");` – Ben S. Jun 01 '18 at 11:22

1 Answers1

0

Problem solved by following this answer: header('Content-Type: image/png'); not working anymore?

The problem was that my .php file was not in ANSI but in UTF-8, after converting it to ANSI it worked.

Ben S.
  • 1
  • 2