Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Feb 2003
    Location
    munich, germany, old europe
    Posts
    16
    Thanks
    0
    Thanked 0 Times in 0 Posts

    problem with image uploader/resizer

    hi, i have a problem with my image uploader/reziser

    it generates a thumbnail and a larger one, that can also be rezised.

    my problem is: this is only suitable for images that are originally larger than the thumbnail. because in case that they are smaller they become stretched when the tumbnail is generated.

    so i need a part in the script that checks if the original is smaller then the values chosen for thumbnails. and if this is true, it should not rezise the thumbnail.
    here comes the code

    PHP Code:
    function gmfilename($uplfile_name$filename$extension)
    ...

           if(
    $extension == jpg)
            {
                 if(
    function_exists(imagejpeg) && $chk[1] == 1)
                  {
                       
    $imgptr imagecreatefromjpeg("$sourcefile");
                       if(
    $imgptr)
                        {
                             
    imggetsize($imgptr, &$x, &$y);
                             
    imgnewsize($x$y, &$newx, &$newy);
                             if(
    function_exists(imagecreatetruecolor) && $gdversion == 2)
                              {
                                   
    $destptr imagecreatetruecolor($newx$newy);
                              }
                             else
                              {
                                   
    $destptr imagecreate($newx$newy);
                              }
                             
    imagecopyresized($destptr$imgptr0,   0,   0,   0$newx$newy$x$y);
                             
    imagejpeg($destptr$sourcefile$quality);
                             
    imagedestroy($imgptr);
                             
    imagedestroy($destptr);
                        }
                       else
                        {
                             echo 
    "$msg[53]";
                        }
                  }
                 else
                  {
                       echo 
    "$msg[54]";
                  }
            }
       ....                          }
                             else
                              {
                                   
    $destptr imagecreate($newx$newy);
                              }
                             
    imagecopyresized($destptr$imgptr0,   0,   0,   0$newx$newy$x$y);
                             
    imagepng($destptr$sourcefile$quality);
    ...

     function 
    imggetsize($imgptr$x$y)
      {
           
    $x imagesx($imgptr);
           
    $y imagesy($imgptr);
      }

     function 
    imgnewsize($x$y$newx$newy)
      {
           global 
    $resizemode;

           if(
    $resizemode == 1)
            {
                 if(
    $x $y)
                  {
                       
    $verh $x $y;
                       
    $newy $newx $verh;
                  }
                 else
                  {
                       
    $verh $y $x;
                       
    $newy $newx $verh;
                  }
            }
           elseif(
    $resizemode == 2)
            {
                 if(
    $x $y)
                  {
                       
    $verh $x $y;
                       
    $newx $newy $verh;
                  }
                 else
                  {
                       
    $verh $y $x;
                       
    $newx $newy $verh;
                  }
            }
      }... 
    thanx for your answers!

  • #2
    New Coder
    Join Date
    Feb 2003
    Posts
    56
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Dunno where are your "values chosen for thumbnail", but I created some just to examplify:

    Code:
    $valueForThumbnailX = 80;
    $valueForThumbnailY = 80;
    
    imggetsize($imgptr, &$x, &$y);
    
    if ($x < $valueForThumbnailX && $y < $valueForThumbnailY){
        $newx = $x;
        $newy = $y;
    }else{
       newImageSize(...)
    }
    was this what you wanted? All you have to do is give newx and newy the same values as x and y...


  •  

    Posting Permissions

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