IMPORTANT!

Snipt is going open source. We've toyed with this idea for quite a while, and have finally decided it's the right way to move forward.

A few things:
  • The entire Snipt source code will be released on GitHub under the 3-clause BSD License on Friday, September 10th.
  • While we'd like to think we're perfect, we realize we're only human. By open sourcing the software that runs this website, certain bugs or security flaws may be discovered that could compromise the privacy of your snipts.
  • Only the Lion Burger team will be able to push commits to the Snipt.net site. Contributors should send a pull request to add new features or submit patches.
  • By using this site, you agree not to be too angry or take any legal action against Lion Burger should this whole thing go up in flames some day.
  • Follow us on Twitter for updates.
I agree, close this message
Sign up to create your own snipts, or login.

Latest 100 public snipts » damonky's snipts The latest snipts from damonky.

showing 1-1 of 1 snipts
  • scale and crop an image to best fit a defined set of dimensions
    function autoCrop($file, $height, $width){
    
         //load the image file
    
         $img = false;
    
         $img = imagecreatefromjpeg($file);
    
         //quit if not loaded
    
         if(!$img){
    
              return false;
    
         }
    
         //get the image dimensions
    
         $curr = @getimagesize($file);
    
     
         $perc_w = $width / $curr[0];
    
         $perc_h = $height / $curr[1];
    
     
    
         if(($width > $curr[0]) || ($height > $curr[1])){
    
              return;
    
         }
    
     
    
         if($perc_h > $perc_w){
    
              //taller
    
              $width = $width;
    
              $height = round($curr[1] * $perc_w);
    
         } else {
    
              //wider
    
              $height = $height;
    
              $width = round($curr[0] * $perc_h);
    
         }
    
         //output
    
         $nwimg = imagecreatetruecolor($width, $height);
    
         imagecopyresampled($nwimg, $img, 0, 0, 0, 0, $width, $height, $curr[0], $curr[1]);
    
         imagejpeg($nwimg, $file);
    
     
    
         imagedestroy($nwimg);
    
         imagedestroy($img);
    
     
    
    }
    

    copy | embed

    0 comments - tagged in  posted by damonky on Jul 24, 2009 at 4:28 a.m. EDT
Sign up to create your own snipts, or login.