View Full Version : Comparing Image Sizes?

11-03-2007, 04:39 PM

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 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;

11-03-2007, 05:02 PM
foreach ($images as $x) {
list($width, $height, $type, $attr) = getimagesize($x);
$newarray[$width*$height] = $x;

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