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

Extract numbers from a unicode string...

Quick extract numbers from a unicode string......

Validate phone number...

Chek if a phone numbers is valid, according to its syntax (should be: "+390523599314"). True if it's valid, False otherwise function is_valid_phone( $phone ) { if ( $phone[0] != "+" ) { ...

Detect leap year...

Detect leap year for gregorian and shamsi date. function gLeapYear($year) { if (($year % 4 == 0) and (($year % 100 != 0) or ($year % 400 == 0))) return true; else return ...

Random string generator...

Random string generator. Optionally, you can give it a desired string length. function rnd_string($len = 24) { $str = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; $str...