#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    18
    Rep Power
    0
    I want to have an option on my site to upload images. I then want to have PHP (or something) make a thumbnail version of the image automatically.

    Is this possible and how?
    Thanks.
  2. #2
  3. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,642
    Rep Power
    4476
    here's some stuff i found on another forum:

    This can be done if the image is GIF (I'm not sure with other formats) ... But, if it realy GIF, u can use :

    function ImageCopyResized()

    U can see the full explaination in www.php.net, but if it'w not GIF, maybe Java servlet can do that ... But if you want to resize it with Image Magick, well ... I never use that application before ... and I don't know how php can communicate with that.

    Alex

    Comment

    From: LexZEUS
    Date: Wednesday, July 12 2000 - 09:03PM PDT

    Ok, I have checked it in www.php.net ... it can be done if the image is JPEG,GIF, or PNG other format I'm not sure ... Try this code :

    <?
    $input_file = "big.gif"; // modify the value yourself
    $output_file = "small.gif"; // modify the value yourself
    $size=GetImageSize($input_file);
    // $size[0] = width
    // $size[1] = hieght
    // $size[2] = flag : 1='GIF', 2='JPG', 3='PNG'
    // $size[3] = string "HEIGHT=xxx WIDTH=xxx"

    if ($size[2]==1) // if GIF
    $im_in = ImageCreateFromGif($input_file);
    if ($size[2]==2) // if JPEG
    $im_in = ImageCreateFromJPEG($input_file)
    if ($size[2]==3) // if PNG
    $im_in = ImageCreateFromPNG($input_file)

    $new_width = (int) $size[0]/3;
    $new_height = (int) $size[1]/3;
    $im_out = ImageCreate($new_width,$new_height);

    ImageCopyResized($im_out,$im_in,0,0,0,0,$new_width,$new_height,$size[0],$size[1]);

    if ($size[2]==1) // if GIF
    ImageGif($im_out,$output_file);
    if ($size[2]==2) // if JPEG
    ImageJPEG($im_out,$output_file);
    if ($size[2]==3) // if PNG
    ImagePNG($im_out,$output_file);

    ImageDestroy($im_in);
    ImageDestroy($im_out);

    print "<IMG SRC="$input_file"> <BR>";
    print "<IMG SRC="$output_file"> <BR>";
    ?>

    If you want to use this code, u must install GD library, it is in http://www.boutell.com

    Alex
  4. #3
  5. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,642
    Rep Power
    4476
    that example i just copies lookes like it's missing some brackets in it's if... statements, but you should get the idea...

Similar Threads

  1. Resizing images with PHP causes images to be cut off
    By lotrtrotk in forum PHP Development
    Replies: 4
    Last Post: February 4th, 2004, 01:19 PM
  2. Resizing user uploaded images
    By Ian Griffiths in forum Software Design
    Replies: 0
    Last Post: September 17th, 2003, 02:53 PM
  3. Resizing PNG images with PHP
    By luigi_uk in forum PHP Development
    Replies: 1
    Last Post: August 12th, 2003, 05:57 AM
  4. rename uploaded images with set pattern
    By Sotonin in forum PHP Development
    Replies: 2
    Last Post: July 6th, 2003, 01:08 PM
  5. resizing images from database
    By bernardi_p in forum PHP Development
    Replies: 3
    Last Post: April 22nd, 2003, 05:02 PM

IMN logo majestic logo threadwatch logo seochat tools logo