前段时间,我写了一个方法,从一个在线社区上传的图片中读取EXIF数据。在我从图片中获得方向后,我将文件旋转到正确的方向。我的脚本中只有一小部分:
public function rotate($sourceFile, $targetFile, $orienation)
{
switch($orienation){
case 3: $degrees = '180'; break;
case 6: $degrees = '90'; break;
case 8: $degrees = '270'; break;
default: $degrees = '0';
}
$file = $sourceFile . DS . $targetFile;
$rotate = GlobalConfig::BIN_IMAGICK_CONVERT . ' -rotate ' . $degrees . ' ' . $file . ' ' . $file;
exec($rotate);
}我的脚本起作用了。但我的问题是,像facebook这样的大公司如何处理上传的照片的轮换?因为我的解决方案肯定不是最好的。
发布于 2012-04-23 16:43:47
我认为更好的方法是使用GD库,代码是这样的
// input
$image = 'myfile.jpg';
//read orientation information from EXIF
$exif = exif_read_data($filename);
$ort = $exif['IFD0']['Orientation'];
//then based on $ort you can determine the rotation degree,
//check the link below for more info
//rotation degree
$degrees = 180;
// create "image object"
$source = imagecreatefromjpeg($image) ;
// rotate
$rotate = imagerotate($source, $degrees, 0) ;
// set the header
header('Content-type: image/jpeg') ;
// output
imagejpeg($rotate) ;更多信息:Exif Orientation Tag
https://stackoverflow.com/questions/10277258
复制相似问题