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

UTF8 string length counter...

The best way to determine the character count of a UTF8 string. function strlen_utf8( $str ) { return mb_strlen( $str, 'UTF-8' ); }   //or... function strlen_utf8( $str ) { $c = 0;...

Number Format...

Format a number with grouped thousands......

SQL escape string function...

Escapes special characters in a string for use in an SQL statement. howewer it check get_magic_quotes_gpc function is enable or no. if true , it strips string from slashes and escaped string from spec...

Change timestamp to custom format...

Use this function for change timestamp to custom format......