Results 1 to 3 of 3

Thread: Resizing an Image?

  1. #1
    Join Date
    Jan 2007
    Posts
    94
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question Resizing an Image?

    Well, i allow users to upload images... and each of these images are going to be the center, main content on separate pages. But, of course I don't want huge massive pictures throwing off my layout. But then again, they're not like thumbnails or anything. So, I was googling "resize image php" and i came across some pretty hefty scripts... so my question is:

    What's the difference between these???

    I'm trying to figure out if I need a script or if i can just get by on the easy one... thanks!

    Seems pretty simple....
    PHP Code:
    <img src "$blahheight "50%" width "50%"
    Seems wayyy complex compared to the first....
    PHP Code:
    <?php

    function imageResize($width$height$target) {

    //takes the larger size of the width and height and applies the  
    formula accordingly...this is so this script will work  
    dynamically with any size image

    if ($width $height) {
    $percentage = ($target $width);
    } else {
    $percentage = ($target $height);
    }

    //gets the new value and applies the percentage, then rounds the value
    $width round($width $percentage);
    $height round($height $percentage);

    //returns the new sizes in html image tag format...this is so you
    can plug this function inside an image tag and just get the

    return "width=\"$width\" height=\"$height\"";

    }

    ?>


    <?php 
    $mysock 
    getimagesize("images/sock001.jpg");
    ?>

    <img src="images/sock001.jpg" <?php imageResize($mysock[0],  
    $mysock[1], 150); ?>>
    ?>
    Thanks!

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Well; from the looks of it, they both pretty much do the same thing. The first code will make the image half the size (both width and height) of the image linked to (in the image tag); as compared to the second one which will resize it based upon some division and rounding (otherwise known as Math).

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Jan 2007
    Posts
    94
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    really? is that what it's called?? lol

    anyway, my question was, would the results be any different between the two

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •