foochuck Posted April 24, 2008 Share Posted April 24, 2008 I have about 20 images on my php page. I'd like to somehow have PHP add up the total width of the pixels of each image. Is this possible? Thanks FOO Quote Link to comment Share on other sites More sharing options...
BlueSkyIS Posted April 24, 2008 Share Posted April 24, 2008 The answer is: yes. Quote Link to comment Share on other sites More sharing options...
foochuck Posted April 24, 2008 Author Share Posted April 24, 2008 Touche'... Can someone give me any tips on how to accomplish this? I'm not sure what functions to use or where to even start... Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 24, 2008 Share Posted April 24, 2008 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. Quote Link to comment Share on other sites More sharing options...
foochuck Posted April 24, 2008 Author Share Posted April 24, 2008 Thanks DarkWater, I'll give that a try. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 24, 2008 Share Posted April 24, 2008 Just put in the right variables before you come back here and say "OMG IT DOESN'T WORK". =P Quote Link to comment Share on other sites More sharing options...
foochuck Posted April 24, 2008 Author Share Posted April 24, 2008 Yes sir. Thanks again. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 24, 2008 Share Posted April 24, 2008 No problem. =) Quote Link to comment Share on other sites More sharing options...
foochuck Posted April 24, 2008 Author Share Posted April 24, 2008 No problem. =) Can I throw one more twist at you? I'd like to figure out the tallest "height" out of all of the images in my array as well. How can I accomplish this? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 24, 2008 Share Posted April 24, 2008 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. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 25, 2008 Share Posted April 25, 2008 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; Quote Link to comment Share on other sites More sharing options...
foochuck Posted April 25, 2008 Author Share Posted April 25, 2008 FYI - Shouldn't the function be getimagesize rather than get_image_size ? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 25, 2008 Share Posted April 25, 2008 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 Quote Link to comment Share on other sites More sharing options...
foochuck Posted April 25, 2008 Author Share Posted April 25, 2008 One other thing - I think $image_dim[1] should be $image_dim[0] - because I need the width attribute, not height. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted April 25, 2008 Share Posted April 25, 2008 You said height: Can I throw one more twist at you? I'd like to figure out the tallest "height" out of all of the images in my array as well. How can I accomplish this? =P [0] is for width though if you do need it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.