SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    May 2007
    Posts
    163
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Image upload dimension vs. quality

    I want to have users of a site upload their pictures
    to a database which will then be displayed in a profile
    template,i'm using a fixed dimension in the template.
    Since I have no control over the dimension of pictures
    from users,I'm afraid the quality of the displayed pictures
    will be affected by forcing them all to a fixed dimension.
    Is there any way to fix this with the php upload script
    or some other way to handle this.
    Thanks.

  2. #2
    play of mind Ernie1's Avatar
    Join Date
    Sep 2005
    Posts
    1,252
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
     $uploadedfile $_FILES['userfile']['tmp_name'];
     
    $src imagecreatefromjpeg($uploadedfile);
     list(
    $width$height) = getimagesize($uploadedfile);
     
    $newwidth 100;
     
    $newheight = ($height $width) * 100;
     
    $tmp imagecreatetruecolor($newwidth$newheight);
     
    imagecopyresampled($tmp$src0000$newwidth$newheight$width$height);
     
    $img "images/" $_FILES['userfile']['name'];
     
    $t 1;
     while(
    file_exists($img)){
         
    $img "images/" $_FILES['userfile']['name'];
         
    $img substr($img0strpos($img".")) . "-$tstrstr($img".");
         
    $t++;
         }
     
    imagejpeg($tmp$img100);
    //insert into table set image_path='$img'... 
    my mobile portal
    ghiris.ro


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
  •