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 Link to comment https://forums.phpfreaks.com/topic/102811-php-image-help/ Share on other sites More sharing options...
BlueSkyIS Posted April 24, 2008 Share Posted April 24, 2008 The answer is: yes. Link to comment https://forums.phpfreaks.com/topic/102811-php-image-help/#findComment-526619 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... Link to comment https://forums.phpfreaks.com/topic/102811-php-image-help/#findComment-526622 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. Link to comment https://forums.phpfreaks.com/topic/102811-php-image-help/#findComment-526624 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. Link to comment https://forums.phpfreaks.com/topic/102811-php-image-help/#findComment-526633 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 Link to comment https://forums.phpfreaks.com/topic/102811-php-image-help/#findComment-526635 Share on other sites More sharing options...
foochuck Posted April 24, 2008 Author Share Posted April 24, 2008 Yes sir. Thanks again. Link to comment https://forums.phpfreaks.com/topic/102811-php-image-help/#findComment-526641 Share on other sites More sharing options...
DarkWater Posted April 24, 2008 Share Posted April 24, 2008 No problem. =) Link to comment https://forums.phpfreaks.com/topic/102811-php-image-help/#findComment-526648 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? Link to comment https://forums.phpfreaks.com/topic/102811-php-image-help/#findComment-526656 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. Link to comment https://forums.phpfreaks.com/topic/102811-php-image-help/#findComment-526659 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; Link to comment https://forums.phpfreaks.com/topic/102811-php-image-help/#findComment-526689 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 ? Link to comment https://forums.phpfreaks.com/topic/102811-php-image-help/#findComment-526744 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 Link to comment https://forums.phpfreaks.com/topic/102811-php-image-help/#findComment-526746 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. Link to comment https://forums.phpfreaks.com/topic/102811-php-image-help/#findComment-526754 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. Link to comment https://forums.phpfreaks.com/topic/102811-php-image-help/#findComment-526755 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.