Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Apr 2007
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Comparing Image Sizes?

    Hello,

    I was trying to find a way to compare image sizes (DIMENSIONS).

    I have the following code, but I am not sure how I go about comparing them.

    I have an array of images, I need to get thier dimensions, and determine whichever is the largest, it would then need to be moved to the front of the array. I have an array_remove function, and theres another function (Can't recall the name atm) that will add it back in.

    I just need help getting the largest image (in terms of dimensions not filesize).

    Thanks for any help!

    PHP Code:
                        <?php foreach ($images as $x) {
                            list(
    $width$height$type$attr) = getimagesize($x);
                            if (
    $width $top_w) {
                                
    $top_w $x;
                            }
                            if (
    $height $top_h) {
                                
    $top_h $x;
                            }
                        }
                        echo 
    $top_w;
                        echo 
    $top_h
    ?>

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    PHP Code:
    foreach ($images as $x) {
        list(
    $width$height$type$attr) = getimagesize($x);
        
    $newarray[$width*$height] = $x;
    }
    krsort($newarray);

    foreach(
    $newarray as $key => $value){
        echo 
    'Size (area): ' $key '<br />';



  •  

    Posting Permissions

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