Hello I am beginning to explore the image stuff in PHP. I was trying something real simple: Creating an image, and sending it directly to the browser. But somehow I mess it up. Please help .. Regards, Snicher <html><head><title>PHP fun</title></head><body> <SCRIPT LANGUAGE="PHP"> $picName = "funstuff.png"; // Size $picWidth = 320; $picHeight = 240; $myPic = imagecreatetruecolor($picWidth, $picHeight); $bgCol = ImageColorAllocate($myPic, 225, 225, 225); for ( $myX = 0; $myX < $picWidth; $myX++) { for ( $myY = 0; $myY < $picHeight; $myY++) { //$newColor = ImageColorDeAllocate($myPic, rand(0,255), rand(0,255), rand(0,255)); $newColor = ImageColorAllocate($myPic, rand(0,255), rand(0,255), rand(0,255)); //$newColor = ImageColorAllocate($myPic, 60, 200, 111); imagesetpixel($myPic, $myX, $myY, $newColor); } } header("Content-type: image/png"); imagePNG($myPic); ImageDestroy($myPic); </SCRIPT> </body></html> PHP:
<SCRIPT LANGUAGE="PHP"> header("Content-type: image/png"); $picName = "funstuff.png"; // Size $picWidth = 320; $picHeight = 240; $myPic = imagecreatetruecolor($picWidth, $picHeight); $bgCol = ImageColorAllocate($myPic, 225, 225, 225); for ( $myX = 0; $myX < $picWidth; $myX++) { for ( $myY = 0; $myY < $picHeight; $myY++) { //$newColor = ImageColorDeAllocate($myPic, rand(0,255), rand(0,255), rand(0,255)); $newColor = ImageColorAllocate($myPic, rand(0,255), rand(0,255), rand(0,255)); //$newColor = ImageColorAllocate($myPic, 60, 200, 111); imagesetpixel($myPic, $myX, $myY, $newColor); } } imagePNG($myPic); ImageDestroy($myPic); </SCRIPT> PHP:
wow, that was fast. Thanks guys! Hey, is it possible to include some html, or is that method image only?
The function is for images only. To include HTML, you have to remember that HTML itself doesn't have images in it.... it only has links to images. Therefore, PHP can't do it as you are thinking, either. What you have to do is have your PHP script create the HTML that then points the browser to another PHP script for the actual image itself. It's late here, so hopefully that makes sense.