bunnyali2013 Posted November 30, 2012 Share Posted November 30, 2012 (edited) 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); ?> Edited November 30, 2012 by bunnyali2013 Quote 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 Quote 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"); Quote 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? Quote 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); ?> Quote 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. Quote 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"? Quote 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. Quote Link to comment https://forums.phpfreaks.com/topic/271405-php-gd-library-error/#findComment-1396592 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.