If statment for image upload width

4 posts by 2 authors in: Forums > CMS Builder
Last Post: February 2, 2012   (RSS)

By Mikey - February 1, 2012

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.

<?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 ?>

Re: [zick] If statment for image upload width

By aev - February 2, 2012

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.


<?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-

Re: [zick] If statment for image upload width

By aev - February 2, 2012

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-