Jump to content

Php Gd Library Error


bunnyali2013

Recommended Posts

Well, I have an image ans I want to write a text on it. The issue is, it is saying, image cannot be displayed because it contains errors. Refer to the screenshot below as attachment.

 

Here the codes:

 

<img src="images/img.jpg" width="500" height="300">

 

<?php
header ("Content-type: image/jpeg");
$string = "This is my text";
$font = 4;
$width = imagefontwidth($font) * strlen($string) ;
$height = imagefontheight($font) ;
$im = imagecreatefromjpeg("images/img.jpg");
$x = imagesx($im) - $width ;
$y = imagesy($im) - $height;
$backgroundColor = imagecolorallocate ($im, 255, 255, 255);
$textColor = imagecolorallocate ($im, 0, 0,0);
imagestring ($im, $font, $x, $y, $string, $textColor);
imagejpeg($im);
?>

post-133078-0-05229800-1354282293_thumb.jpg

Link to comment
https://forums.phpfreaks.com/topic/271405-php-gd-library-error/
Share on other sites

Yes its on, in fact I made this:

 

<?php
ini_set('display_errors', 1);
error_reporting(E_ALL);
//header ("Content-type: image/jpeg");
$string = "This is my text";
$font = 4;
$width = imagefontwidth($font) * strlen($string) ;
$height = imagefontheight($font) ;
$im = imagecreatefromjpeg("images/img.jpg");
$x = imagesx($im) - $width ;
$y = imagesy($im) - $height;
$backgroundColor = imagecolorallocate ($im, 255, 255, 255);
$textColor = imagecolorallocate ($im, 0, 0,0);
imagestring ($im, $font, $x, $y, $string, $textColor);
imagejpeg($im);
?>

Based on the filename (index.php) in the attached error output, you are apparently trying to output the dynamic image on a html page. That doesn't work. The only thing you can output for the request for an image is the content-type header followed by the image data.

 

The src="..." attribute in your <img tag must be to the .php file that outputs the dynamic image.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.