svgmx5 Posted February 27, 2010 Share Posted February 27, 2010 I'm trying to optimize a set of images that are rendered with php. The images are stored on the server and the file path to the images are saved on a database. I'm currently using a script i found online, and every-time i load the page to display the images, all i get are weird characters instead of images, and the following error message: warning: Cannot modify header information - headers already sent by (output started at /home/content/w/a/r/warbudz10/html/images.php:13) in /home/content/w/a/r/warbudz10/html/images.php on line 315 Here is the script that i'm using, i hope someone can help me out with this <?php $images = "images/gallery/"; # Location of small versions $sql = "SELECT * FROM gallery ORDER BY imageID ASC"; $run = mysql_query($sql) or die (mysql_error()); $num = mysql_num_rows($run); while($fetch = mysql_fetch_array($run)){ $imageID = $fetch['imageID']; $fileName = $fetch['imagePath']; $imageTitle = $fetch['imageTitle']; $img = imagecreatefromjpeg('images/gallery/'.$fileName.''); header('Content-Type: image/jpeg'); imagejpeg($img, null, 75); imagedestroy($img); ?> <div class="galleryImgContainer"> <div class="galleryImgWrapper"> <a href="<?php echo ' '.$images.$fileName.' ' ;?>" rel="lightbox[roadtrip]"> <img src="<?php echo ' '.$img.' ' ;?>" width="157" height="127" border="0" /> </a> </div> <div class="imgTitle"> <h1><a href="#"><?php echo ' '.$imageTitle.' ' ;?></a></h1> </div> </div> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/193552-problems-optimizing-images/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 27, 2010 Share Posted February 27, 2010 You cannot output image data directly on a HTML page. You must use an <img src="URL of an image" alt=""> HTML tag for each image you put onto a HTML page. The 'URL of an image' that you put into the src= attribute must be to your .php script that outputs the Content-type: header, followed by the image data. Link to comment https://forums.phpfreaks.com/topic/193552-problems-optimizing-images/#findComment-1018905 Share on other sites More sharing options...
svgmx5 Posted February 27, 2010 Author Share Posted February 27, 2010 isn't that what im doing here? <img src="<?php echo ' '.$img.' ' ;?>" width="157" height="127" border="0" /> Link to comment https://forums.phpfreaks.com/topic/193552-problems-optimizing-images/#findComment-1018906 Share on other sites More sharing options...
PFMaBiSmAd Posted February 27, 2010 Share Posted February 27, 2010 Nope, that's not even a URL. It's an image resource returned by a GD library function. Link to comment https://forums.phpfreaks.com/topic/193552-problems-optimizing-images/#findComment-1018909 Share on other sites More sharing options...
svgmx5 Posted February 27, 2010 Author Share Posted February 27, 2010 so what should i do then? Link to comment https://forums.phpfreaks.com/topic/193552-problems-optimizing-images/#findComment-1018910 Share on other sites More sharing options...
PFMaBiSmAd Posted February 27, 2010 Share Posted February 27, 2010 Someone already answered that - You must use an <img src="URL of an image" alt=""> HTML tag for each image you put onto a HTML page. The 'URL of an image' that you put into the src= attribute must be to your .php script that outputs the Content-type: header, followed by the image data. Link to comment https://forums.phpfreaks.com/topic/193552-problems-optimizing-images/#findComment-1018912 Share on other sites More sharing options...
alpine Posted February 27, 2010 Share Posted February 27, 2010 I suspect you might be looking for something like this (simplified example) <?php // img_src.php $id = $_GET['id']; // make GET id db safe // query db for filename, content type and path based on requested photo id header('Content-Type: image/jpeg'); echo file_get_contents('path/to/file/filename.jpg') ?> Then call img_get.php for each photo like this to display it <img src="img_src.php?id=foo" /> Link to comment https://forums.phpfreaks.com/topic/193552-problems-optimizing-images/#findComment-1018919 Share on other sites More sharing options...
svgmx5 Posted February 27, 2010 Author Share Posted February 27, 2010 yea thats kinda what i'm looking for..i think i got what the other guy was saying earlier....Thanks! Link to comment https://forums.phpfreaks.com/topic/193552-problems-optimizing-images/#findComment-1018927 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.