bunnyali2013 Posted November 30, 2012 Share Posted November 30, 2012 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); ?> Link to comment https://forums.phpfreaks.com/topic/271405-php-gd-library-error/ Share on other sites More sharing options...
Barand Posted November 30, 2012 Share Posted November 30, 2012 Comment out the header() and run the script on its own Link to comment https://forums.phpfreaks.com/topic/271405-php-gd-library-error/#findComment-1396441 Share on other sites More sharing options...
bunnyali2013 Posted November 30, 2012 Author Share Posted November 30, 2012 I get rubbish code. I mean the codes of the image. I did this: //header ("Content-type: image/jpeg"); Link to comment https://forums.phpfreaks.com/topic/271405-php-gd-library-error/#findComment-1396443 Share on other sites More sharing options...
Barand Posted November 30, 2012 Share Posted November 30, 2012 No error messages? Is error reporting turned on? Link to comment https://forums.phpfreaks.com/topic/271405-php-gd-library-error/#findComment-1396445 Share on other sites More sharing options...
bunnyali2013 Posted November 30, 2012 Author Share Posted November 30, 2012 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 https://forums.phpfreaks.com/topic/271405-php-gd-library-error/#findComment-1396447 Share on other sites More sharing options...
PFMaBiSmAd Posted November 30, 2012 Share Posted November 30, 2012 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 https://forums.phpfreaks.com/topic/271405-php-gd-library-error/#findComment-1396457 Share on other sites More sharing options...
bunnyali2013 Posted November 30, 2012 Author Share Posted November 30, 2012 Huhh, if aI understand, the src should be like this: src="index.php"? Link to comment https://forums.phpfreaks.com/topic/271405-php-gd-library-error/#findComment-1396460 Share on other sites More sharing options...
Christian F. Posted December 1, 2012 Share Posted December 1, 2012 Not quite. Create a new file, call it (for example) image.php, and move the above code into it. Then you can use <img src="image.php"> in your HTML code. Link to comment https://forums.phpfreaks.com/topic/271405-php-gd-library-error/#findComment-1396592 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.