ctechguy Posted December 16, 2009 Share Posted December 16, 2009 I'm quite new to Object Oriented PHP. What I'm trying to do is draw some images but also have other content on the page. include('images.php'); //New Image set $im=new images(); //Sends headers and images don't work echo "hello"; //New rect $us=$ge->rect("Title"); $us->setDimensions(300,300); $us->setBgColor('#606060'); $us->createImage(); There are 2 classes; images which extends rect. In the createImage() it draws an image on index.php?img=0 but only if no other headers are sent yet. function createImage(){ if ($_GET['img']==$this->id){ ... imagepng($this->im); ImageDestroy ($im);} Is there anyway to draw this objects and also have content. I tried to see if I could draw the images through the images class like images.php?img=0 but that didn't work. I was also thinking if there was a way to send an if back to index from constructor and destructor. This is probably really confusing sorry, an help is appreciated Link to comment https://forums.phpfreaks.com/topic/185388-drawing-images-in-classes/ Share on other sites More sharing options...
teamatomic Posted December 17, 2009 Share Posted December 17, 2009 You can play around with output buffering but its not really the easiest thing until you've had some experience using it as its not really intuitive. Use the example I give you here. You can output html, create an image and display it and continue on. All without an error. *But if you move the comments up one line you will output the image and stop. There is an implied exit() after the use of imagedestroy() if you use an image header. <?php echo "hello"; //header("Content-type: image/gif"); $im = imagecreate(200, 200); $green = imagecolorallocate($im, 0, 255, 0); $red = imagecolorallocate($im, 255, 0, 0); $blue = imagecolorallocate($im, 0, 0, 255); imagerectangle($im, 20, 20, 120, 90, $green); imagerectangle($im, 50, 60, 160, 120, $red); imagefilltoborder($im, 61, 61, $red, $blue); imagegif($im,'c:/home/tester2.gif'); //imagegif($im); imagedestroy($im); ?> <br>An image<br> <img src="http://localhost/tester2.gif" border=0> <br> We can continue on! HTH Teamatomic Link to comment https://forums.phpfreaks.com/topic/185388-drawing-images-in-classes/#findComment-979012 Share on other sites More sharing options...
ctechguy Posted December 17, 2009 Author Share Posted December 17, 2009 Thanks so much for pointing me in the right direction. Link to comment https://forums.phpfreaks.com/topic/185388-drawing-images-in-classes/#findComment-979184 Share on other sites More sharing options...
nafetski Posted December 17, 2009 Share Posted December 17, 2009 Another way to do it would be output your HTML as you normally would, then in an <img> tag have the src point to your php script that will generate your images. <img src="/dir/to/php/script/imageScript.php" /> Both will work tho Link to comment https://forums.phpfreaks.com/topic/185388-drawing-images-in-classes/#findComment-979240 Share on other sites More sharing options...
mattal999 Posted December 17, 2009 Share Posted December 17, 2009 Might want to look into image caching though, as this will hog server resources. An example being: function isCached($filename) { if(file_exists($filename) && (time() - filemtime($filename)) < 3600) { return true; } else { return false; } } if(!isCached('images/tester2.gif')) { generateImage('images/tester2.gif'); } echo "<img src=\"images/tester2.gif\" />"; Link to comment https://forums.phpfreaks.com/topic/185388-drawing-images-in-classes/#findComment-979367 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.