exif数据,php上传图像旋转
我很难实现php代码,它将确保上传的所有照片在上传时都能正确定位 这是我的upload.php函数exif数据,php上传图像旋转,php,upload,rotation,exif,Php,Upload,Rotation,Exif,我很难实现php代码,它将确保上传的所有照片在上传时都能正确定位 这是我的upload.php函数 function process_image_upload($field) { if(!isset($_FILES[$field]['tmp_name']) || ! $_FILES[$field]['name']) { return 'empty'; } $temp_image_path = $_FILES[$field]['tmp_name']; $temp_image_name
function process_image_upload($field)
{
if(!isset($_FILES[$field]['tmp_name']) || ! $_FILES[$field]['name'])
{
return 'empty';
}
$temp_image_path = $_FILES[$field]['tmp_name'];
$temp_image_name = $_FILES[$field]['name'];
list($iwidth, $iheight, $temp_image_type) =
getimagesize($temp_image_path);
if ($temp_image_type === NULL) {
return false;
}
elseif( $iwidth < 400 )
return 'size';
switch ($temp_image_type) {
case IMAGETYPE_GIF:
break;
case IMAGETYPE_JPEG:
break;
case IMAGETYPE_PNG:
break;
default:
return false;
}
$uploaded_image_path = UPLOADED_IMAGE_DESTINATION . $temp_image_name;
move_uploaded_file($temp_image_path, $uploaded_image_path);
$thumbnail_image_path = THUMBNAIL_IMAGE_DESTINATION .
preg_replace('{\\.[^\\.]+$}', '.jpg', $temp_image_name);
$main_image_path = MAIN_IMAGE_DESTINATION . preg_replace('{\\.[^\\.]+$}', '.jpg', $temp_image_name);
$result =
generate_image_thumbnail($uploaded_image_path,
$thumbnail_image_path,150,150
); if( $result )
$result =
generate_image_thumbnail($uploaded_image_path,$main_image_path,400,400,
true);
return $result ? array($uploaded_image_path, $thumbnail_image_path) :
false;
}
if(isset($_POST['upload'])):
$result = process_image_upload('image');
if ($result === false) {
update_option('meme_message','<div class="error" style="margin-
left:0;"><p>An error occurred while processing upload</p></div>');
} else if( $result === 'empty')
{
update_option('meme_message','<div class="error" style="margin-
left:0;"><p>Please select a Image file</p></div>');
}
elseif( $result === 'size')
{
update_option('meme_message','<div class="error" style="margin-
left:0;"><p>Image width must be greater than 400px;</p></div>');
}
else {
update_option('meme_message','<div style="margin-left:0;"
class="updated"><p>Image uploaded successfully</p></div>');
$guploaderr = false;
$count = intval(get_option('meme_image_count'));
update_option('meme_image_count', $count+1);
}
endif;
功能处理\图像\上传($field)
{
如果(!isset($_文件[$field]['tmp_名称']))| |!$_文件[$field]['name']))
{
返回“空”;
}
$temp_image_path=$_文件[$field]['tmp_名称'];
$temp_image_name=$_文件[$field]['name'];
列表($iwidth、$iheight、$temp\u image\u type)=
getimagesize($temp\u image\u path);
if($temp\u image\u type==NULL){
返回false;
}
elseif($iwidth<400)
返回“大小”;
开关($temp\u image\u类型){
案例图像类型\u GIF:
打破
case IMAGETYPE_JPEG:
打破
案例IMAGETYPE_PNG:
打破
违约:
返回false;
}
$uploaded_image_path=上传的_image_目的地。$temp_image_名称;
移动上传的文件($temp\u image\u path,$upload\u image\u path);
$thumbnail\u image\u path=缩略图\u image\u目标。
preg_replace('{\\.[^\.]+$}','.jpg',$temp_image_name);
$main_image_path=main_image_DESTINATION.preg_replace('{\\.\\.\.]+$}','.jpg',$temp_image_name);
$result=
生成\u图像\u缩略图($u图像\u路径,
$thumbnail\u image\u路径,150150
);如果($结果)
$result=
生成图像缩略图($Upload\u image\u path,$main\u image\u path,400400,
正确的);
返回$result?数组($upload\u image\u path,$thumbnail\u image\u path):
虚假的;
}
如果(isset($_POST['upload']):
$result=处理图像上传(“图像”);
如果($result==false){
update_option('meme_message','p>处理上载时出错');
}如果($result=='empty'),则为else
{
更新选项(“meme_消息”,请选择一个图像文件);
}
elseif($result==='size')
{
更新选项('meme_message','图像宽度必须大于400px;);
}
否则{
更新选项('meme_message','p>图像上传成功');
$guploader=false;
$count=intval(get_选项('meme_image_count');
更新_选项('meme_image_count',$count+1);
}
endif;
这里有一些php,我知道它可以用来旋转。。。但我不知道如何实施
<?php
$image =
imagecreatefromstring(file_get_contents($_FILES['image_upload']
['tmp_name']));
$exif = exif_read_data($_FILES['image_upload']['tmp_name']);
if(!empty($exif['Orientation'])) {
switch($exif['Orientation']) {
case 8:
$image = imagerotate($image,90,0);
break;
case 3:
$image = imagerotate($image,180,0);
break;
case 6:
$image = imagerotate($image,-90,0);
break;
}
}
// $image now contains a resource with the image oriented correctly
?>