image resize

Discussion in 'PHP' started by saunders1989, Feb 13, 2010.

  1. #1
    I am really struggling with this part of my website and i cant seem to figure it out. what i need to do is literally resize an image. at the moment when the user goes to the one of the gallerys a script is called which is named imageResize.php. (let me know if you would like to see the script) what i need to do is when the user clicks the thumbnail it takes them to another page called image.php and shows the full sized image but i need to shrink it down but i havent a clue how. any ideas would be great. i would like to use the same imageResize script but change it so i can use my own values.

    this is the code i use for the thumbnail page:

    while ($row = $result->fetch_assoc()) {
    
    echo "<a href=\"image.php?id=" . $row['id'] . "\">";
    echo "<img src=\"imageResize.php?imageFilename=" . $row['name'] . "&maxHeight=90,&maxWidth=150\" />\n";
    echo "</a>\n";
    
    }
    PHP:
    and image.php looks like this:

    while($row = $result->fetch_array()) { 
    
    	echo "<div id=\"image\">\n";
        echo '<img src="' . $row['image_path'] . '" />';
    	echo "</div>\n";
    	
        echo '<p>' . $row['desc'] . '</p>';
    } 
    
    PHP:
    any ideas on how to do this would be great. thanks for your time!
     
    saunders1989, Feb 13, 2010 IP
  2. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #2
    imageresize.php should do the following:

    1) sanitize input

    2) check for the existence of the image

    3) if not found, exit with an HTTP error code 404

    4) if found, use Imagick::resizeImage to scale it to the desired size. See the PHP manual page on this method for an example in the comments section.

    5) ideally, cache the resized image so it can be displayed directly next time

    6) send the HTTP header for an image (e.g., Content-Type: image/jpeg)

    7) send the image data

    8) exit
     
    SmallPotatoes, Feb 13, 2010 IP
  3. saunders1989

    saunders1989 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    my imageresize script works fine. what i need to do is somehow resize my image that is displayed on image.php using the same script but changing the name so i can change the numbers
     
    saunders1989, Feb 13, 2010 IP