Resize image function

Resize image function for jpg format. $mood between max and min. if you choose max, this mean max size of image is $ta otherwise min size of image is $ta.

function makeTheThumb( $ppath, $ta, $mood )
{
   list( $w, $h ) = getimagesize( $ppath );
   $orig = imagecreatefromjpeg( $ppath );
   if ( ( strcmp( $mood, 'width' ) == 0 ) || ( ( $w > $h ) ^ ( strcmp( $mood, 'min' ) == 0 ) ) ) {
      $tw = $ta;
      $th = round( $tw * $h / $w );
   }
   else {
      $th = $ta;
      $tw = round( $th * $w / $h );
   }
   $timg = imagecreatetruecolor( $tw, $th );
   imagecopyresampled( $timg, $orig, 0, 0, 0, 0, $tw, $th, $w, $h );
   imageinterlace( $timg, 1 );
   imagejpeg( $timg, 'out.jpg', 100 );
   imagedestroy( $timg );
   return "ENDED;$tw;$th";
}
 
makeTheThumb( 'test.jpg', 150, 'max' );

Tags

No tag here.

Recommended pages

Email Address Checker...

This function check if an e-mail address is valid or not. function valid_email($email) { return preg_match('/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/', $email);...

Detect file extension function...

This function is used to find the file extension also you can use pathinfo() function for get information about a file path. function ext($file_name) { return substr($file_name, strrpos($fi...

Encrypt and Decrypt function with different outputs...

Encrypt function return different value with each execute but decrypt function return input value. for example: first execute: encrypt('hello') => 'axxdfg34', decrypt('axxdfg34') return 'hello'...

How to created mixed arguments function...

This way useful for create mixed arguments function. function foo() { $args = func_get_args(); print_r($args); }   foo(1, 1256, 6, 17); //mixed ...   -------------------Out-...