Jump to content

problems optimizing images


svgmx5

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.