Canadian Posted December 12, 2009 Share Posted December 12, 2009 I'm trying to go through a tutorial on generating images using the GD2 library but I keep getting an error. I've used Xammp for my install on my Mac. I have not altered any default settings. Below I have listed my GD settings from phpinfo(), my source code, and the error I am getting. Any help would be greatly appreciated. Thanks ********GD Settings From phpinfo()******** gd GD Support enabled GD Version bundled (2.0.34 compatible) FreeType Support enabled FreeType Linkage with freetype FreeType Version 2.3.5 GIF Read Support enabled GIF Create Support enabled JPEG Support enabled libJPEG Version 6b PNG Support enabled libPNG Version 1.2.32 WBMP Support enabled XBM Support enabled Directive Local Value Master Value gd.jpeg_ignore_warning 0 0 ********Source Code******** <?php // Here we are setting up the image variables $height = 200; $width = 200; $im = imagecreatetruecolor($width, $height); $white = imagecolorallocate($im, 255, 255, 255); $blue = imagecolorallocate($im, 0, 0, 64); // Here is where we draw the image imagefill($im, 0, 0, $blue); imageline($im, 0, 0, $width, $height, $white); imagestring($im, 4, 50, 150, 'PWP', $white); // Here is where we send the image to the screen... Header ('Content-type: image/png'); imagepng($im); // Clean up the resources... imagedestroy($im); ?> ********Error Message******** Warning: Cannot modify header information - headers already sent by (output started at /Applications/XAMPP/xamppfiles/htdocs/phplearn/php_mysql_bible/chapter22/chapter_22_notes.php:10) in /Applications/XAMPP/xamppfiles/htdocs/phplearn/php_mysql_bible/chapter22/chapter_22_notes.php on line 46 �PNG IHDR��":9��IDATx���Kr�0E���K.\n����!��]/����s�eP����Eݻ�_�E}�~a�:v}<����t�-��3,a�z�Kآ�m���\oa [t�=X��vKآ��a [T_,a�*+�%lQM��-*���EeU����X��Kآ��a [�S��-z�YX�m���E/�%l����衞��-�_gX�IKآA����%l�n ,a+qca [YK�J�X�V�&���5��������4͆%l�h,a+Ak` [�[K� �JX�V�������1���pY�%l��,a+P�` [Q2K� �EX�����g���9Ӱ�-�Y�%l��,a�a>` [�rK�r�'X���������!���-�y�%l��1,a�p�a [VsK�2YX�������e�P��-3E�%l�( ,a�@1a [�K�ZZdX�ֺ�����������e�%l�-,akb�` [�JKؚRFX��������5���ae�%l� X�����7`��W�����V�������u2`� [g�^�jXa�-`����U�jViت Xa�<`Յ�U�JVK�:X�ak?`�����u*l�Xg��f���^V�������ǀ�3l}��a���-kP�֨����2�������r��֤��ּR��������ւ2�֚��ֲb���������B�����������"�������b�����Ѽ���\����������<�������|����������\���������,�������l�V�ںHW_�vO3u�|�<���u|�^'gaV_�^��T2k��u_��|k��P����22}3b��V�8A%+|��Y�Mê��̘�Zn��VH���]ºߋ�$��p�\¢�V�r���a�c���ز��;�m�M�lŢ�&�[�J�L[���4[�J�[���[�J�h[���P[�J�8[��� [�!��E�[���������W�l���bX��y[��N���-`�^Ͷ�E���`XTT�-`QiU��E���UhXT]�-`QK���E�����cXt�w��Eg۴,�Ы-`Q��l���hXԳo[�)��v��f3�C��<IEND�B`� Quote Link to comment https://forums.phpfreaks.com/topic/184933-gd2-problems-help-please/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 12, 2009 Share Posted December 12, 2009 Read the error - output started at ..../chapter_22_notes.php:10 (line 10) Your file is outputting some content at or before line 10 in the file. You cannot output anything but another header before a header() statement. You would need to find and eliminate whatever is causing the output that is occurring before the header() statement. You would would need to post the full file if you want anyone in the forum to help find what the offending content is. Quote Link to comment https://forums.phpfreaks.com/topic/184933-gd2-problems-help-please/#findComment-976249 Share on other sites More sharing options...
Canadian Posted December 12, 2009 Author Share Posted December 12, 2009 Here is everything in that file... ********Source Code******** <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Chapter 16 Notes</title> </head> <body> <?php /* ****************CREATING IMAGES**************** There are four basic steps to creating images in PHP. 1. Creating a canvas image on which to work. 2. Drawing shapes or printing text on that canvas 3. Outputting the final graphic 4. Cleaning up resources Here is an example below. */ // Here we are setting up the image variables $height = 200; $width = 200; $im = imagecreatetruecolor($width, $height); $white = imagecolorallocate($im, 255, 255, 255); $blue = imagecolorallocate($im, 0, 0, 64); // Here is where we draw the image imagefill($im, 0, 0, $blue); imageline($im, 0, 0, $width, $height, $white); imagestring($im, 4, 50, 150, 'PWP', $white); // Here is where we send the image to the screen... Header ('Content-type: image/png'); imagepng($im); // Clean up the resources... imagedestroy($im); //phpinfo(); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/184933-gd2-problems-help-please/#findComment-976253 Share on other sites More sharing options...
PFMaBiSmAd Posted December 13, 2009 Share Posted December 13, 2009 Everything you posted that is before the first opening <?php tag and after the last closing ?> tag is the offending content. When you output an image (the content-type header followed by the image data) you cannot output anything else. To output an image on a web page you must put the URL of the image into an <img src="..." alt=""> tag - http://w3schools.com/html/html_images.asp For the case were you are dynamically producing the image using GD functions, the URL you put into the src="..." attribute is the URL of your .php file that contains the GD code. Quote Link to comment https://forums.phpfreaks.com/topic/184933-gd2-problems-help-please/#findComment-976278 Share on other sites More sharing options...
Canadian Posted December 19, 2009 Author Share Posted December 19, 2009 Ahhh... That makes so much sense. Thank you PFMaBiSmAd Quote Link to comment https://forums.phpfreaks.com/topic/184933-gd2-problems-help-please/#findComment-980556 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.