Main
Index
Search
Posts
Who's
Online
Log
In

Home: Products: CMS Builder:
If statment for image upload width

 

 


zick
User

Feb 1, 2012, 8:27 PM

Post #1 of 4 (244 views)
Shortcut
If statment for image upload width Can't Post

Can some tell me if it's possible to check the height of an uploaded image and if it exceeds a specific height (160px), then the image is skipped and the next uploaded image is displayed that falls within the allowed height?

Example:
My "Create thumbnail : " is set to:
Width: 240px
Height: 240px

My Div, (<div class="PhotoContainer">) I'm loaded the images into is set to:
width:196px;
height:160px;

So if I upload an image that is 6x4" it would re-size to 240px wide by 160px height and this image would display.
However if I uploaded a vertical image that is 4x6" it would re-size to 160px wide by 240px height and since it exceeds the allowed height of (160px) it is skipped and the next image that meets the height limitation is allowed to be displayed.


Code
<?php foreach ($photoRecord['photos'] as $upload): ?> 
<div class="PhotoContainer">
<?php if ($upload['hasThumbnail']): ?>

<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" border="0" class="Photo" />

<?php endif ?>
</div>
<?php endforeach ?>



aev
User

Feb 1, 2012, 11:57 PM

Post #2 of 4 (227 views)
Shortcut
Re: [zick] If statment for image upload width [In reply to] Can't Post

Hi,

add the red line to your code and see if that does what you want. The "continue" tells the "foreach" to skip the current cycle continue with the next.



Code
<?php foreach ($photoRecord['photos'] as $upload): ?>  
<?php if ($upload['height'] > 160) continue; // Skip image if height is greater than 160 ?>
<div class="PhotoContainer">
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" border="0" class="Photo" />
<?php endif ?>
</div>
<?php endforeach ?>



-aev-


zick
User

Feb 2, 2012, 12:42 AM

Post #3 of 4 (221 views)
Shortcut
Re: [aev] If statment for image upload width [In reply to] Can't Post

Thanks aev

It works like a charm.
I really appreciate the help!

Zick


aev
User

Feb 2, 2012, 1:23 AM

Post #4 of 4 (214 views)
Shortcut
Re: [zick] If statment for image upload width [In reply to] Can't Post

Good!


Maybe this could be of interest as well:
http://www.interactivetools.com/iforum/gforum.cgi?post=86562;search_string=print_r;t=search_engine#86562

Remember to adjust the array names ($selectedRecord/$categoryRecords) to reflect your array names.


-aev-