The Little Guy Posted February 11, 2010 Share Posted February 11, 2010 When I place the following into a class, the image doesn't build correctly, I don't know why... The code (not in class): $str = $_GET['str']; $font = '../../../incl/fonts/dirty_and_classic.ttf'; $lineCount = 40; // Size of the font $fontSize = 160; // Height of the image $height = 90; // Width of the image $width = 500; $img_handle = imagecreate ($width, $height) or die ("Cannot Create image"); // Set the Background Color RGB $backColor = imagecolorallocate($img_handle, 37, 39, 45); // Set the Text Color RGB $txtColor = imagecolorallocate($img_handle, 255, 255, 255); $textbox = imagettfbbox($fontSize, 0, $font, $str) or die('Error in imagettfbbox function'); $x = 25; $y = 50; imagettftext($img_handle, $fontSize, 0, $x, $y, $txtColor, $font , $str) or die('Error in imagettftext function'); header('Content-Type: image/jpeg'); imagejpeg($img_handle, NULL, 100); imagedestroy($img_handle); When I move it out of the class it works fine. In class: <?php class Image{ public $font = '../../../incl/fonts/dirty_and_classic.ttf'; public function __construct(){ //$this->font = $_SERVER['DOCUMENT_ROOT'].'/incl/fonts/dirty_and_classic.ttf'; } public function buildImage($str, $save = false, $filename = null){ $lineCount = 40; // Size of the font $fontSize = 160; // Height of the image $height = 90; // Width of the image $width = 500; $img_handle = imagecreate ($width, $height) or die ("Cannot Create image"); // Set the Background Color RGB $backColor = imagecolorallocate($img_handle, 37, 39, 45); // Set the Text Color RGB $txtColor = imagecolorallocate($img_handle, 255, 255, 255); //echo getcwd();exit; $str = "Ryan Naddy"; $textbox = imagettfbbox($fontSize, 0, $this->font, $str) or die('Error in imagettfbbox function'); $x = 25; $y = 50; imagettftext($img_handle, $fontSize, 0, $x, $y, $txtColor, $this->font , $str) or die('Error in imagettftext function'); header('Content-Type: image/jpeg'); imagejpeg($img_handle, NULL, 100); imagedestroy($img_handle); } } ?> When I run it as a class: include '../../../classes/Image.php'; $img = new Image(); $img->buildImage("Ryan Naddy"); All that happens is I get a broken image. Anyone know why this happens? Quote Link to comment https://forums.phpfreaks.com/topic/191736-dynamic-image-doesnt-work-when-it-is-in-a-class/ Share on other sites More sharing options...
Alex Posted February 11, 2010 Share Posted February 11, 2010 Comment out the Content-type header change and see what error it's giving you. Quote Link to comment https://forums.phpfreaks.com/topic/191736-dynamic-image-doesnt-work-when-it-is-in-a-class/#findComment-1010593 Share on other sites More sharing options...
The Little Guy Posted February 11, 2010 Author Share Posted February 11, 2010 No error: http://www.nawdog.com/images/dynamic/image.php?str=Ryan Quote Link to comment https://forums.phpfreaks.com/topic/191736-dynamic-image-doesnt-work-when-it-is-in-a-class/#findComment-1010598 Share on other sites More sharing options...
PFMaBiSmAd Posted February 11, 2010 Share Posted February 11, 2010 Are you developing and debugging code on a system with error_reporting set to E_ALL and display_errors set to ON so that php WOULD report and display all the errors it detects? Quote Link to comment https://forums.phpfreaks.com/topic/191736-dynamic-image-doesnt-work-when-it-is-in-a-class/#findComment-1010643 Share on other sites More sharing options...
The Little Guy Posted February 11, 2010 Author Share Posted February 11, 2010 Are you developing and debugging code on a system with error_reporting set to E_ALL and display_errors set to ON so that php WOULD report and display all the errors it detects? Yes I am... Quote Link to comment https://forums.phpfreaks.com/topic/191736-dynamic-image-doesnt-work-when-it-is-in-a-class/#findComment-1010766 Share on other sites More sharing options...
The Little Guy Posted February 12, 2010 Author Share Posted February 12, 2010 When I run the script (not from the class), if I have an include in the script, it doesn't work, but if I comment out the include it does work. The include looks like this: include '../../../classes/Image.php'; and all that is, is my class Quote Link to comment https://forums.phpfreaks.com/topic/191736-dynamic-image-doesnt-work-when-it-is-in-a-class/#findComment-1011158 Share on other sites More sharing options...
The Little Guy Posted February 12, 2010 Author Share Posted February 12, 2010 GOT IT! I had 2 extra spaces after my closing php tag in my class file Quote Link to comment https://forums.phpfreaks.com/topic/191736-dynamic-image-doesnt-work-when-it-is-in-a-class/#findComment-1011162 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.