SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2004
    Location
    philippines
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question scale down the image

    hi guys! can anyone help me on how to rescale the uploaded image from the database. this is the scenario, i am developing forum that will accept avatar from the user. it comes to my mind that what if the user uploaded very large scale of image. but my forum only accepts maximum 100x100 pixels but the said image is 200x150pixels. i tried to use fixed scale for the image but the result doesnt look good because it stretched the image. plz help me guys. thanks.

  2. #2
    Forum Buyer
    Join Date
    Jun 2004
    Location
    United States
    Posts
    811
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    google imagemajick and GD library
    Founder/Admin of a pretty decent chat forum
    Download free winterboard themes for your iPhone
    I run sites powered by vbulletin and one about the HTC Jetstream.

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2004
    Location
    San Diego, CA (USA)
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    heres a good function that i use for resizing images:

    PHP Code:
    /*
    $img is the source jpg image
    $w is the maximum width that the resized image will be
    $h is the maximum height that the resized image will be
    */
    function resize_jpg($img,$w,$h){
        
           
    $imagedata getimagesize($img);
        
           if (
    $w && ($imagedata[0] < $imagedata[1])) {
                 
    $w = ($h $imagedata[1]) * $imagedata[0];
           } else {
                 
    $h = ($w $imagedata[0]) * $imagedata[1];
           }
        
           
    $im2 ImageCreateTrueColor($w,$h);
        
           
    $image ImageCreateFromJpeg($img);
        
           
    imagecopyResampled ($im2$image0000$w$h$imagedata[0], $imagedata[1]);
        
           
    ImageJpeg($im2$img100);
        

    this is written with functions from the gd library.

    i hope i helped.

    edit: this function only supports JPG images... and for your situation, it needs to support GIF images (as it sounds).... i will look into this more.

  4. #4
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Heres a decent tutorial if you wanted to try it!

    http://www.weberdev.com/get_example-3938.html


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •