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
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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.