旋转图像90度PHP

时间:2017-01-25 17:49:01

标签: php image

我正在开发一个将图像上传到服务器的ios应用程序,相机胶卷的文件大小太大,所以我使用以下功能将缩略图保存到服务器。

如何在保存之前将图像旋转90度?

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 );
  
}

1 个答案:

答案 0 :(得分:1)

使用imagerotate功能:http://php.net/manual/en/function.imagerotate.php

您可以在imagejpeg之前添加以下行:

$thumb = imagerotate ( $thumb, 90 , 0 );
相关问题