Thanks goetz for your time, that's very kind of you to write the code. if i
have any more questions i shall post it under new thread.


"Goetz Lohmann" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Geckodeep schrieb:
> > Thanks Goetz
> >
> > But how can I apply this having:
> >
> > Path to the folder is $folder='images/repor_images';       // path to
the
> > image.
> >
> > My 9image variables are $image1, $image2, $image3,. and the code to call
the
> > image
> >
> > <?php print "<img alt='$title' border=0 width= '103' heigth = '70'
> > src=\"$folder/$image1\">" ?>
> >
> > Thanks again.
>
> I should do coding the whole page I gues ;-)
>
> First of all some things to mention about:
> 1. Better store only filenames in the database and leave
>    the images in the directory, cause you have to copy then
>    to a location anyway to get it by an browser
> 2. Use an array of $image[] instead of numbering them
>    like $image1, $image2, ... (you have to use eval to
>    work with the numbers or have to write the code more
>    than once !)
>
> Ok here it goes:
>
> <?php
>   // guess you have JPEG images
>   // --------------
>   $nr = 1;        // start numbering your images
>   $maxsize = 150; // maximum size in one direction
>   // ---------------
>   while($nr <= 9) {
>     $img = @imagecreatefromjpeg ("$folder/$image[$nr]"); // try to open
>     if (!$im) {
>       echo "ERROR loading image $folder/$image[$nr] ";
>       exit 1;
>     } else {
>       $imagehw = GetImageSize($img);
>       $w = $imagehw; // width
>       $h = $imagehw; // height
>       // prevent division by zero
>       if (($h ==0) || ($w==0)) exit;
>       // get new size according to max size
>       if ($h>$w) {
>         $new_h = $maxsize; // new height
>         $new_w = (int) (($maxsize * $w) / $h); // casting to int !
>       } else {
>         $new_w = $maxsize; // new width
>         $new_h = (int) (($maxsize * $h) / $w); // casting to int !
>       }
>       // build dummy image
>       $thumb = imagecreate ($new_w, $new_h);
>       // resize old image
>       ImageCopyResized($thumb,$img,0,0,0,0,$new_w,$new_h,$w,$h);
>       // maybe use tempname() to generate a temporary file name or
>       // create name of thumbnail file like: *.jpg ==> *.png
>       $tumbnail=substr($image[$nr],0,strrpos($image[$nr],".")).".png";
>       // save png image to same directory as jpg
>       @imagepng ($thumb,"$folder/$tumbnail"); // hope we could write
>       // leave the temporary data ...
>       ImageDestroy($img);
>       ImageDestroy($thumb);
>       // finished work
>       // -------------------
>       // show image
>       echo "<img alt=\"$title\" border=\"0\" width=\"$new_w\" ".
>            "heigth=\"$new_h\" src=\"$folder/$tumbnail\" >";
>     }
>     $nr++; // next image
>   }
> ?>
>
> maybe there might better ways but thats just a fast hack to work ...
>
>
>
> --
>  @  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

Reply via email to