Xampp & php GD2?

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Xampp & php GD2?

Postby MEGA_MIND » 08. January 2019 20:09

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
MEGA_MIND
 
Posts: 1
Joined: 08. January 2019 20:06
XAMPP version: 7.3.0
Operating System: 8.1

Re: Xampp & php GD2?

Postby modoran » 14. January 2019 13:25

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);
    ?>
modoran
 
Posts: 4
Joined: 31. December 2018 11:49
XAMPP version: 1.2.3
Operating System: windows 10 x64


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 61 guests