rondog Posted July 26, 2008 Share Posted July 26, 2008 I am trying to make it so when you go to this php file it generates it and displays the image. I have this right now and according to my browser its a jpg, but I just see a string of text. <?php header("Content-type: image/jpeg"); include "connect.php"; $today = date("Y-m-d"); $today = strtotime($today); $query = mysql_query("SELECT event_image FROM de_featuredevent WHERE '$today' BETWEEN start_date AND end_date") or die(mysql_error()); $row = mysql_fetch_array($query); $img = $row['event_image']; imagecreatefromjpeg("featuredimages/".$img); ?> http://drewestate.com/new/2008/loadfeaturedevent.php Quote Link to comment https://forums.phpfreaks.com/topic/116781-solved-making-this-php-file-output-as-a-jpg/ Share on other sites More sharing options...
DeanWhitehouse Posted July 26, 2008 Share Posted July 26, 2008 is this the full page code ,and the extension on the image seems to be .php in the page Quote Link to comment https://forums.phpfreaks.com/topic/116781-solved-making-this-php-file-output-as-a-jpg/#findComment-600536 Share on other sites More sharing options...
rondog Posted July 26, 2008 Author Share Posted July 26, 2008 Yea thats all of the code for that php file. The extension of the image is jpg. The PHP should be able to output a jpeg. $img = $row['event_image']; is going to be equal to event1.jpg so the image path is now: "featuredimages/event1.jpg" and I am using imagecreatefromjpeg to do that. Is that the wrong function? I've tried imagejpeg as well and same thing. Quote Link to comment https://forums.phpfreaks.com/topic/116781-solved-making-this-php-file-output-as-a-jpg/#findComment-600540 Share on other sites More sharing options...
papaface Posted July 26, 2008 Share Posted July 26, 2008 Your code should work.... hmmm... Quote Link to comment https://forums.phpfreaks.com/topic/116781-solved-making-this-php-file-output-as-a-jpg/#findComment-600547 Share on other sites More sharing options...
rondog Posted July 26, 2008 Author Share Posted July 26, 2008 Here is my phpinfo file if that tell anything about my GD. It says its installed and JPEG is enabled. http://drewestate.com/new/2008/info.php Quote Link to comment https://forums.phpfreaks.com/topic/116781-solved-making-this-php-file-output-as-a-jpg/#findComment-600548 Share on other sites More sharing options...
DarkWater Posted July 27, 2008 Share Posted July 27, 2008 You're not actually saving the image resource and using imagejpeg() to OUTPUT the image. Quote Link to comment https://forums.phpfreaks.com/topic/116781-solved-making-this-php-file-output-as-a-jpg/#findComment-600572 Share on other sites More sharing options...
rondog Posted July 27, 2008 Author Share Posted July 27, 2008 oh duh haha..i got it <?php include "connect.php"; $today = date("Y-m-d"); $today = strtotime($today); $query = mysql_query("SELECT event_image FROM de_featuredevent WHERE '$today' BETWEEN start_date AND end_date") or die(mysql_error()); $row = mysql_fetch_array($query); $src = "featuredeventimages/".$row['event_image']; header("Content-type: image/jpeg"); $img = imagecreatefromjpeg($src); $img = imagejpeg($img); ?> Quote Link to comment https://forums.phpfreaks.com/topic/116781-solved-making-this-php-file-output-as-a-jpg/#findComment-600580 Share on other sites More sharing options...
PFMaBiSmAd Posted July 27, 2008 Share Posted July 27, 2008 If you are not actually minupulating the image using GD functions, using GD to open an image an output it is a huge waste of memory and time. Just use the readfile() function. Quote Link to comment https://forums.phpfreaks.com/topic/116781-solved-making-this-php-file-output-as-a-jpg/#findComment-600590 Share on other sites More sharing options...
DarkWater Posted July 27, 2008 Share Posted July 27, 2008 Oh yeah. I was going to ask why you actually needed GD. Quote Link to comment https://forums.phpfreaks.com/topic/116781-solved-making-this-php-file-output-as-a-jpg/#findComment-600593 Share on other sites More sharing options...
rondog Posted July 27, 2008 Author Share Posted July 27, 2008 yeah I dont know..thats the first thing that came to mind when I needed to output a file. Im still learning :] readfile sounds like the right way to go Quote Link to comment https://forums.phpfreaks.com/topic/116781-solved-making-this-php-file-output-as-a-jpg/#findComment-600643 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.