SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Commander Awesome DevonWright's Avatar
    Join Date
    Jul 2004
    Location
    Saskatoon, Canada
    Posts
    242
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Determine Image Size

    Is there a way that I'd be able to determine if an image is greater than a certain size? I haven't run into anything like this before.

    What I want to do is to display a person's avatar, however, if it's bigger than a certain size I want to size it down [I was thinking about just hard coding it to 100x100 but I figured if someone's avatar isn't square dimensions then it wouldn't look good].

    Is there a way to determine the width and height of an image? Or am I hooped?
    Ultimate X:
    Brand spanking new layout, very pretty.
    All of your Ultimate Marvel needs.

  2. #2
    Commander Awesome DevonWright's Avatar
    Join Date
    Jul 2004
    Location
    Saskatoon, Canada
    Posts
    242
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    (let's do some searching before asking a question next time Devon shall we?)

    getimagesize();

    PHP Code:
    <?php
    list($width$height$type$attr) = getimagesize("img/flag.jpg");
    echo 
    "<img src=\"img/flag.jpg\" $attr alt=\"getimagesize() example\" />";
    ?>
    Is this a good example of what I'd want?
    Ultimate X:
    Brand spanking new layout, very pretty.
    All of your Ultimate Marvel needs.

  3. #3
    Commander Awesome DevonWright's Avatar
    Join Date
    Jul 2004
    Location
    Saskatoon, Canada
    Posts
    242
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    and then

    PHP Code:
    imagesx();

    imagesy(); 

    Erm, I guess sorry to have bothered you, if you have a better way feel free to post (still pretty new with the PHP game)
    Ultimate X:
    Brand spanking new layout, very pretty.
    All of your Ultimate Marvel needs.

  4. #4
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $max_img_size_x '200';
    $max_img_size_y '200';

    list(
    $width$height$type$attr) = getimagesize($your_img_path);

    if(
    $width $max_img_size_x && $height $max_img_size_y) {
    echo 
    "The picture is too big";
    } else {
    echo 
    "<img src='blah.png'>";



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
  •