Re: Help - Outputting Thumbnails



<alt.php>
<nickwired>
<27 Jun 2006 21:15:26 -0700>
<1151468126.264709.137200@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>

A novice like myself has one question :

I have a few images users uploaded to a mySQL database. How can I out
them as thumbnails.

Any help would be appreciated.


<?php

$file="demo.jpg";

$img_name="images/$file";
$new_name="thumbs/$file";
$max_width=120;
$max_height=70;
$size=GetImageSize($img_name);
$width_ratio=($size[0] / $max_width);
$height_ratio=($size[1] / $max_height);

if($width_ratio >=$height_ratio)
{
$ratio = $width_ratio;
}
else
{
$ratio = $height_ratio;
}
$new_width=($size[0] / $ratio);
$new_height=($size[1] / $ratio);
$src_img=ImageCreateFromJPEG($img_name);
$thumb=ImageCreateTrueColor($new_width,$new_height);
ImageCopyResampled($thumb,$src_img,0,0,0,0,($new_width-1),($new_height-
1),$size[0],$size[1]);
ImageJPEG($thumb,$new_name);
ImageDestroy($src_img);
ImageDestroy($thumb);

print "<img src=$new_name>";

?>

The above is some old code i had on the hard disk .

If memory serves $img_name="images/$file"; is where it gets the large
image from and $new_name="thumbs/$file"; is where it puts the thumbnail
you just created .

$max_width=120;
$max_height=70;

You can change these maximum thumbnail size defaults to suit afterwards
if wanted .


--
www.emailuser.co.uk/?name=KRUSTOV
.



Relevant Pages

  • Re: Picture or video hosting?
    ... The optional extra info is stored, but doens't show in the browse section ... I'm reading up on PHP based picture manipulation (for thumbnails), ...
    (rec.pyrotechnics)
  • Re: thumbnails as links...?
    ... >> The php code I'm using sets everything up nicely with thumbnails, etc., ... > Do you offer website design services without knowing HTML??? ... design - but I normally have someone else do my php. ...
    (alt.php)
  • Photo Album
    ... I am very new to php, ... picture photo album in file photo.php. ... thumbnails, it reloads the page and displays the image you clicked on. ... I'd like to see a one php file solution ...
    (comp.lang.php)
  • Re: [PHP] Re: Dealing with ImageMagick from PHP
    ... It handles taking photographs, categorizing them, making thumbnails of them, and allows parentsto view the photos and order them. ... Anyway -- the clients decided they wanted me to do some work on the image quality, so I finally decided to move up to ImageMagick v.6.3.4. ... I call ImageMagick from a "exec" call in PHP. ... They've asked if anything can be done about that, but I think I've optimized the shell script as much as possible. ...
    (php.general)
  • Re: Dealing with ImageMagick from PHP
    ... It handles taking photographs, categorizing them, making thumbnails of them, and allows parentsto view the photos and order them. ... Anyway -- the clients decided they wanted me to do some work on the image quality, so I finally decided to move up to ImageMagick v.6.3.4. ... I call ImageMagick from a "exec" call in PHP. ... They've asked if anything can be done about that, but I think I've optimized the shell script as much as possible. ...
    (php.general)