views:

52

answers:

1

I have a image gallery, my requirement is to apply diffrent image sizes to all image my html markup is

<div class="post-attacthe-img"> 
<ul>
<li><a><img src="1.png"/></a></li>
<li><a><img src="2.png"/></a></li>
<li><a><img src="3.png"/></a></li>
<li><a><img src="4.png"/></a></li>
<li><a><img src="5.png"/></a></li>
<li><a><img src="6.png"/></a></li>
<li><a><img src="7.png"/></a></li>
<li><a><img src="8.png"/></a></li>
<li><a><img src="9.png"/></a></li>
<li><a><img src="10.png"/></a></li>

</ul>
</div>

Example like: 1 image if its size is 500X500, 2 image is 200X200,
again
3 image is 200X200, 4 image is 500X500
5 image is again 500X 500 and 6 image is 100X100, 7 Image is 100X100
Now again
8 image is 100X100, 9 Image is 100X100, 10 image is 500X500

Now the problem is i have to apply it timbthub.php which is a image resizing script.

+1  A: 
function viewResize($img_path,$maxwidth,$maxheight){
        $img_array = @getimagesize($img_path);
        if(is_array($img_array)){
            list($orig_width, $orig_height, $type)=$img_array;           
            if ($orig_width > $maxwidth){
                $h = $maxwidth * ($orig_height / $orig_width);
                $w = $maxwidth;
                if($h>$maxheight){
                    $h = $maxheight;
                    $w = $maxheight * ( $orig_width / $orig_height);
                }
            }
            elseif($orig_height > $maxheight){
                $h = $maxheight;
                $w = $maxheight * ($orig_width / $orig_height);
                if($w>$maxwidth){
                    $h = $maxwidth * ($orig_height / $orig_width);
                    $w = $maxwidth;
                }
            }
            else{
                $w = $orig_width;
                $h = $orig_height;    
            }
            $resize = array();
            $resize['w']=floor($w);
            $resize['h']=floor($h);
            return $resize;
        }
        else{
            return FALSE;
        }
}

usage:

<?php 
$dimensions = viewResize('foto.jpg','120','120');
echo "<img src='foto.jpg' style='width:"$dimensions['w']"px;height:".$dimensions['h']."px;' alt='foto'/>";
?>

if I understand ....

<?php
foreach($fotos_array as $foto){
    $dimensions = viewResize($foto,'120','120');
    echo "<img src='$foto' style='width:"$dimensions['w']"px;height:".$dimensions['h']."px;' alt='foto'/>";     
}
?>
jatt
Wow this works for seprate markup where there is no any loop bt in my condition there is a loop so can't use this all tags are wrap in a foreach.
saorabh
of course you can
jatt
like this foreach ($arrKeys as $arrKey) {echo $image;}
saorabh
Ok but how we can pass the image dimensions.
saorabh
tuto edited see at bottom...
jatt
Thank you Its working
saorabh