Need help: Setting MAX width for an image

Discussion in 'HTML & Website Design' started by webtracker, Nov 3, 2006.

  1. #1
    I have a site with different sized images and I'm displaying them in a table with a fixed width. The problem I'm running into is that if I don't specify a width, the really BIG images push the talbes boundries out past the fixed table dimension. If I set a width, just shy of my fixed table width, it stretches the smaller images past their actual size.

    What I'd like, but don't know how to do it, is:

    RULE 1: Used actual image size.
    RULE 2: If image size exceeds 500px set width = 500px

    Can this be done?

    I'm pulling the images in using a database and I'm using PHP. I'd just like to know if there is anything I can add to this line:

    <img src="<?=HOMEPAGE?>userpics/graphics/thumbnail/<?=$thumbnail?>"/>
     
    webtracker, Nov 3, 2006 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    Do you know if you have th GD library compiled with php?
     
    jestep, Nov 3, 2006 IP
  3. webtracker

    webtracker Peon

    Messages:
    108
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    No, I'm not sure...

    Is there a way for me to check?


    Thanks
     
    webtracker, Nov 3, 2006 IP
  4. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #4
    Make a phpinfo page and see if there is gd section.
     
    jestep, Nov 3, 2006 IP
  5. webtracker

    webtracker Peon

    Messages:
    108
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hi thank...

    Yes it says that it is enabled:

    GD Support enabled
    GD Version bundled (2.0.28 compatible)
    FreeType Support enabled
    FreeType Linkage with freetype
    GIF Read Support enabled
    GIF Create Support enabled
    JPG Support enabled
    PNG Support enabled
    WBMP Support enabled
    XBM Support enabled
     
    webtracker, Nov 3, 2006 IP
  6. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #6
    http://www.phpit.net/article/image-manipulation-php-gd-part2/
    http://www.jaguarpc.com/forums/archive/index.php/t-13229.html

    Here's 2 good topics on how to resize using GD. The second one may be easier for your use.

    Also, if you can, it would be much easier to resize the images so that none are over 500px. Not sure if that is possible for what you are doing. If pictures are uploaded, you can use GD to resize anything as it is being uploaded. This would take some stress off the server, so it doesn't have to use GD for normal page views.

    Basically you should make a simple script to check the image's width. If it is greater than 500, then you should resize it as you wanted to do.
     
    jestep, Nov 4, 2006 IP