Page 1 of 1

Xampp & php GD2?

PostPosted: 08. January 2019 20:09
by MEGA_MIND
hello everyone im new in this community using xampp since 2009
i recently updated xamp just yesterday but the thing is when i use my php script to show image and text over it on online website host then then text on image is
displayed but not in xampp localhost any solutions

i get error on display like

The image “http://wno-host.ddns.net:90/p/” cannot be displayed because it contains errors

the code i use
Code: Select all
<?php
      //Set the Content Type
      header('Content-type: image/jpeg');

      // Create Image From Existing File
      $jpg_image = imagecreatefromjpeg('sunset.jpg');

      // Allocate A Color For The Text
      $white = imagecolorallocate($jpg_image, 255, 255, 255);

      putenv('GDFONTPATH=' . realpath('.'));
        $font = 'Arial.ttf';

      // Set Text to Be Printed On Image
      $text = "This is a sunset!";

      // Print Text On Image
      imagettftext($jpg_image, 25, 0, 75, 300, $white, $font_path, $text);

      // Send Image to Browser
      imagejpeg($jpg_image);

      // Clear Memory
      imagedestroy($jpg_image);
    ?>


output

Image

Re: Xampp & php GD2?

PostPosted: 14. January 2019 13:25
by modoran
This is the fixed PHP script, however it has nothing to do with xampp, it is just a bad php script written by you in the first place:

Code: Select all
<?php
      //Set the Content Type
      header('Content-type: image/jpeg');

      // Create Image From Existing File
      $jpg_image = imagecreatefromjpeg('sunset.jpg');

      // Allocate A Color For The Text
      $white = imagecolorallocate($jpg_image, 255, 255, 255);

      putenv('GDFONTPATH=' . realpath('.'));
        $font = 'Arial.ttf';

      // Set Text to Be Printed On Image
      $text = "This is a sunset!";

      // Print Text On Image
      imagettftext($jpg_image, 25, 0, 75, 300, $white, getenv ("GDFONTPATH")."\\".$font, $text);

      // Send Image to Browser
      imagejpeg($jpg_image);

      // Clear Memory
      imagedestroy($jpg_image);
    ?>