Geckodeep schrieb:
> Hi there I have this problem wondering how to define the size of my images.
> I have this page that has 9 images coming from the database. These images
> are uploaded into a folder and the names are referenced in the DB.
> I pull the image through these tags
> <?php print "<img alt='$title' border=0 width= '103' heigth = '70'
> src=\"$folder/$image1\">" ?>
> and it's ok if the images are rectangular with size 104 x 70,but how will I
> reduce the size of the image having the opposite size 70 x 104 rectangular
> but shorter in length.
>
> Hard coding the size is not the solution for me as these images are coming
> straight from the DB with their actual size.
>
> Having decided the sizes to be either 104 x 70 or 70 x 104, now the trouble
> is how to assignee these values dynamically judging the format of the image.
>
> I've seen different script in resizing the images on the fly but couldn't
> adapt to my needs, as I've 9 image variables ($image1, $image2,..)already
> assigned and I am looking for scripts or solutions in resizing the images on
> the fly by assigning my 9image variables to the resize function.
>
> Thanks once again.
its just mathematic ;-)
<?php
// get size
$imagehw = GetImageSize($img0);
$w = $imagehw[0]; // width
$h = $imagehw[1]; // height
$maxsize = 150; // maximum size in one direction
// prevent division by zero
if ($height==0 || $width==0) exit;
// get new size according to max size
if ($height>$width) {
$new_h = $maxsize; // new height
$new_w = (int) (($maxsize * $width) / $height); // casting to int !
} else {
$new_w = $maxsize; // new width
$new_h = (int) (($maxsize * $height) / $width); // casting to int !
}
// resize image
ImageCopyResized($thumb,$img,0,0,0,0,$new_w,$new_h,$w,$h);
// new thumbnail is in $thumb
?>
--
@ Goetz Lohmann, Germany | Web-Developer & Sys-Admin
\/ ------------------------------------------------------
() He's the fellow that people wonder what he does and
|| why the company needs him, until he goes on vacation.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php