emancipator Posted December 25, 2007 Share Posted December 25, 2007 I am trying to write a very simple image displaying program, I am using HostMonster. The problem being: when i remove the function (ie. move everything outside of the function), everything works fine but when I put everything into the function (ie. code below) and execute it in the body, nothing gets displayed except the link (url). Any idea? Here is the code: <?php header('Content-type: image/jpeg'); function image(){ $filename = 'TEST.JPG'; $image = imagecreatefromjpeg($filename); imagejpeg($image,null,100); } ?> <html> <body> <?php image(); ?> </body> </html> Link to comment https://forums.phpfreaks.com/topic/83102-problem-with-imagejpeg/ Share on other sites More sharing options...
emancipator Posted December 25, 2007 Author Share Posted December 25, 2007 bump Link to comment https://forums.phpfreaks.com/topic/83102-problem-with-imagejpeg/#findComment-423006 Share on other sites More sharing options...
Gamic Posted December 25, 2007 Share Posted December 25, 2007 The script that is outputing an image should be a seperate script from one outputing html. You should do something like this with your html code so that your browser can make a request to the server for the image. <image src="path/to/imageScript.php"> Link to comment https://forums.phpfreaks.com/topic/83102-problem-with-imagejpeg/#findComment-423035 Share on other sites More sharing options...
emancipator Posted December 27, 2007 Author Share Posted December 27, 2007 Thanks for the reply. I still don't quite understand the difference between image operation and say echoing something, and how do I pass function parameters if I can't really "call" the function in html. I guess my question remains how do I execute a function that does image manipulation (like create a thumb size picture page based on a list of pictures). Sorry for being so noob-ish, and thanks in advance for replying. Link to comment https://forums.phpfreaks.com/topic/83102-problem-with-imagejpeg/#findComment-423862 Share on other sites More sharing options...
Barand Posted December 27, 2007 Share Posted December 27, 2007 You need a "thumb.php" script that creates a thumnail size image of the file passed to it <?php $picToResize = $_GET['pic'] $src = imagecreatefromjpeg($picToResize); // resize code here imagejpeg ($thumbImage); imagedestroy($src); imagedestroy($thumb): ?> In your main page you then output a series of img tags to output the thumbnail images, passing the file to process in the query string. EG <?php $images = array ('a.jpg', 'b.jpg', 'c.jpg'); foreach ($images as $picture) { echo "<img src='thumb.php?pic=$picture'>"; } Link to comment https://forums.phpfreaks.com/topic/83102-problem-with-imagejpeg/#findComment-424048 Share on other sites More sharing options...
emancipator Posted December 27, 2007 Author Share Posted December 27, 2007 Thanks for the reply. When I tried this echo "<img src='thumb.php?pic=$picture'>"; It doesn't seem to pass $picture to thumb.php but instead display thumb.php?pic=$picture, which is obviously a broken link. Any ideas? Link to comment https://forums.phpfreaks.com/topic/83102-problem-with-imagejpeg/#findComment-424196 Share on other sites More sharing options...
emancipator Posted December 28, 2007 Author Share Posted December 28, 2007 bump ... again Link to comment https://forums.phpfreaks.com/topic/83102-problem-with-imagejpeg/#findComment-424487 Share on other sites More sharing options...
spiffy577 Posted December 28, 2007 Share Posted December 28, 2007 If it is displaying literally "<img src='thumb.php?pic=$picture'>", just take the $picture out of the string quote, like this: echo "<img src='thumb.php?pic=".$picture." '>"; Although I could be COMPLETELY missing the point but I had the same problem sometimes with keeping the variable within the echo'd string. And btw, I am not exactly an expert on php but isn't image a keyword? So using image as a function name wouldn't work. Change the name to createImage or something... Although again, I could be completely missing the point. hehe... Link to comment https://forums.phpfreaks.com/topic/83102-problem-with-imagejpeg/#findComment-424496 Share on other sites More sharing options...
emancipator Posted December 28, 2007 Author Share Posted December 28, 2007 Thanks, that is a part of the solution but not all. The main problem remains as the PUT and GET action isn't initiated in the img tag but merely passed along as a part of the url. Does this have anything to do with on_load? I am lost... Link to comment https://forums.phpfreaks.com/topic/83102-problem-with-imagejpeg/#findComment-424723 Share on other sites More sharing options...
emancipator Posted December 29, 2007 Author Share Posted December 29, 2007 Bump. Link to comment https://forums.phpfreaks.com/topic/83102-problem-with-imagejpeg/#findComment-425073 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.