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

Edited by bunnyali2013
Link to comment
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);
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.