0

I am developing an ios app which uploads an image to the sever, the file size from the camera roll was too large so I am using the below function to save a thumbnail image to the server.

How would I rotate the image by 90 degrees before it is saved?

function thumbnail( $img, $source, $dest, $maxw, $maxh ) {  

    

    
        $jpg = $source.$img;

    if( $jpg ) {
        list( $width, $height  ) = getimagesize( $jpg ); //$type will return the type of the image
        $source = imagecreatefromjpeg( $jpg );
        
        
        
        echo "WIDTH:".$width." HEIGHT:".$height;

        if( $maxw >= $width && $maxh >= $height ) {
            $ratio = 1;
        }elseif( $width > $height ) {
            $ratio = $maxw / $width;
            
        }else {
            $ratio = $maxh / $height;
            
        }

        $thumb_width = round( $width * $ratio ); //get the smaller value from cal # floor()
        $thumb_height = round( $height * $ratio );

        $thumb = imagecreatetruecolor( $thumb_width, $thumb_height );
        imagecopyresampled( $thumb, $source, 0, 0, 0, 0, $thumb_width, $thumb_height, $width, $height );

        $path = $dest.$img;
        imagejpeg( $thumb, $path, 75 );
        
       
    }
    imagedestroy( $thumb );
    imagedestroy( $source );
  
}
MattBlack
  • 3,616
  • 7
  • 32
  • 58

1 Answers1

1

Use the imagerotate function: http://php.net/manual/en/function.imagerotate.php

You can add the following line before imagejpeg:

$thumb = imagerotate ( $thumb, 90 , 0 );
Antony
  • 1,253
  • 11
  • 19