Jump to content

PHP - Image Help


foochuck

Recommended Posts

Put the picture names in an array and do:

 

foreach ($array_name as $v) {

   $image_dim = get_image_size("/path/to/file/$v.jpg");

   $total += $image_dim[1];

}

 

All the files have to be in the same folder (or all have relative paths to the same folder otherwise it won't work right.

Link to comment
https://forums.phpfreaks.com/topic/102811-php-image-help/#findComment-526624
Share on other sites

 

Change the foreach code to this:

foreach ($array_name as $v) {

    $image_dim = get_image_size("/path/to/file/$v.jpg");

    $total += $image_dim[1];

    $heights[] = $image_dim[1];

}

$highest = current(end(sort($heights, SORT_NUMERIC)));

echo $highest;

 

Rofl, try that.  Kind of convoluted, but I can't think of an easier way right now, although I know there is one.

 

 

Link to comment
https://forums.phpfreaks.com/topic/102811-php-image-help/#findComment-526659
Share on other sites

Woops.  I forgot that sort() and end() don't return an array, but actually pass it by reference.  Here, this code works, I tried it:

 

foreach ($array_name as $v) {

    $image_dim = get_image_size("/path/to/file/$v.jpg");

    $total += $image_dim[1];

    $heights[] = $image_dim[1];

}

 

sort($heights, SORT_NUMERIC);

end($heights);

$highest = current($heights);

echo $highest;

Link to comment
https://forums.phpfreaks.com/topic/102811-php-image-help/#findComment-526689
Share on other sites

Yes yes, I wasn't thinking.  I typed getimagesize on my test script on my server, lol, which is rather ironic.  But the code for getting the max numeric value in an array works fine.  There's probably already a function for it, but it isn't coming to me, so just use that. xD

Link to comment
https://forums.phpfreaks.com/topic/102811-php-image-help/#findComment-526746
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.