简体   繁体   English

将图片旋转90度php

[英]Rotate Image 90 degrees php

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. 我正在开发一个ios应用程序,该应用程序将图像上传到服务器,相机胶卷中的文件大小太大,因此我正在使用以下功能将缩略图图像保存到服务器。

How would I rotate the image by 90 degrees before it is saved? 在保存之前,如何将图像旋转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 ); } 

Use the imagerotate function: http://php.net/manual/en/function.imagerotate.php 使用imagerotate函数: http : imagerotate

You can add the following line before imagejpeg: 您可以在imagejpeg之前添加以下行:

$thumb = imagerotate ( $thumb, 90 , 0 );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM