用到php的exif扩展,需要开启exif

在php.ini文件中去掉exif组件的注释

extension=php_mbstring.dll  //要放在php_exif.dll前面让它先加载
extension=php_exif.dll [exif]
exif.encode_unicode = ISO-8859-15
exif.decode_unicode_motorola = UCS-2BE
exif.decode_unicode_intel = UCS-2LE
exif.encode_jis =
exif.decode_jis_motorola = JIS
exif.decode_jis_intel = JIS
   /**
* Modified Version of cameraUsed, no longer returns date.
*/
private function cameraUsed($imagePath)
{
// The default empty return
$return = array(
'make' => "",
'model' => "",
'exposure' => "",
'aperture' => "",
'iso' => "",
'Orientation' => 1,
); // Check if the variable is set and if the file itself exists before continuing
if ((isset($imagePath)) && (file_exists($imagePath)))
{
// There are 2 arrays which contains the information we are after, so it's easier to state them both
$exif_ifd0 = @read_exif_data($imagePath ,'IFD0' ,0);
$exif_exif = @read_exif_data($imagePath ,'EXIF' ,0); // Ensure that we actually got some information
if (($exif_ifd0 !== false) && ($exif_exif !== false))
{
// Make
if (@array_key_exists('Make', $exif_ifd0))
{
$return['make'] = $exif_ifd0['Make'];
} // Model
if (@array_key_exists('Model', $exif_ifd0))
{
$return['model'] = $exif_ifd0['Model'];
} // Exposure
if (@array_key_exists('ExposureTime', $exif_ifd0))
{
$return['exposure'] = $exif_ifd0['ExposureTime'];
} // Aperture
if (@array_key_exists('ApertureFNumber', $exif_ifd0['COMPUTED']))
{
$return['aperture'] = $exif_ifd0['COMPUTED']['ApertureFNumber'];
} // ISO
if (@array_key_exists('ISOSpeedRatings',$exif_exif))
{
$return['iso'] = $exif_exif['ISOSpeedRatings'];
}
if(@array_key_exists('Orientation',$exif_ifd0)){
$return['Orientation'] = $exif_ifd0['Orientation'];
}
}
} // Return either an empty array, or the details which we were able to extrapolate.
return $return;
} /**
* resize image and don't rotates images have exif info
* @param $pic eg:$_FILES['file']['tmp_name']
* @param $thumb image save path
* @param $thumbwidth
* @param int $quality
*/
private function createThumbnail($pic,$thumb,$thumbwidth, $quality = 100)
{ $im1 = @imagecreatefromjpeg($pic); $exif = $this->cameraUsed($pic);
if(($exif['Orientation'] > 1)) {
switch($exif['Orientation']) {
case 8:
$im1 = @imagerotate($im1,90,0);
break;
case 3:
$im1 = @imagerotate($im1,180,0);
break;
case 6:
$im1 = @imagerotate($im1,-90,0);
break;
}
} $info = @getimagesize($pic); $width = $info[0]; $w2 = @imagesx($im1);
$h2 = @imagesy($im1);
$w1 = ($thumbwidth <= $width) ? $thumbwidth : $width; $h1 = @floor($h2 * ($w1 / $w2)); $im2 = @imagecreatetruecolor($w1,$h1); @imagecopyresampled ($im2,$im1,0,0,0,0,$w1,$h1,$w2,$h2);
$path = addslashes($thumb);
@imagejpeg($im2,$path,$quality);
@imagedestroy($im1);
@imagedestroy($im2);
}

php图片上传旋转压缩方法的更多相关文章

  1. PHP实现图片上传并压缩

    本文实例讲解了PHP图片上传并压缩的实现方法,分享给大家供大家参考,具体内容如下 使用到三个文件 connect.php:连接数据库 test_upload.php:执行SQL语句 upload_im ...

  2. php 图片上传的公共方法(按图片宽高缩放或原图)

    写的用于图片上传的公共方法类调用方法: $upload_name='pic';$type = 'logo_val';$file_name = 'logo_' . $user_id .create_st ...

  3. vuejs开发组件分享之H5图片上传、压缩及拍照旋转的问题处理

    一.前言 三年.net开发转前端已经四个月了,前端主要用webpack+vue,由于后端转过来的,前端不够系统,希望分享下开发心得与园友一起学习. 图片的上传之前都是用的插件(ajaxupload), ...

  4. html + js 实现图片上传,压缩,预览及图片压缩后得到Blob对象继续上传问题

    先上效果 上传图片后(设置了最多上传3张图片,三张后上传按钮消失) 点击图片放大,可以使用删除和旋转按钮 (旋转功能主要是因为ios手机拍照后上传会有写图片被自动旋转,通过旋转功能可以调正) html ...

  5. 图片上传前 压缩,base64图片压缩 Exif.js处理ios拍照倒置等问题

    曾写过在前端把图片按比例压缩不失真上传服务器的前端和后台,可惜没有及时做总结保留代码,只记得js利用了base64位压缩和Exif.js进行图片处理,还有其中让我头疼的ios拍照上传后会倒置等诸多问题 ...

  6. vue下实现input实现图片上传,压缩,拼接以及旋转

    背景 作为一名前端工作人员,相信大家在开发系统的时候,经常有遇到需要这么一种需求,就是需要为用户保存上传的图片,很多小白遇到这个问题的时候,都会虎躯一震,以为会是一个棘手的问题,当你读完这篇文章的时候 ...

  7. 微信sdk 图片上传 两种方法 上传一张显示一张 并附带微信图片放大功能和删除功能

    html <!--上传图片--> <div class="upload-mod"> <div class="up-box" id= ...

  8. H5图片上传、压缩

    1.注册input file标签的onchange事件: 2.检查图片格式: 3.检查图片大小: 4.压缩图片 5.上传图片至服务器: 前端代码: document.getElementById('i ...

  9. iOS图片上传及压缩

    提到从摄像头/相册获取图片是面向终端用户的,由用户去浏览并选择图片为程序使用.在这里,我们需要过UIImagePickerController类来和用户交互. 使用UIImagePickerContr ...

随机推荐

  1. ThinkPHP find大坑 不要随便用

    举例: M("User")->find(3); $m=M("User"); $m->userName="aaa"; $m-> ...

  2. 解析xml数据存入bean映射到数据库的 需求解决过程

    解析xml数据存入bean映射到数据库的 需求解决过程2017年12月19日 15:18:57 守望dfdfdf 阅读数:419 标签: xmlbean 更多个人分类: 工作 问题编辑版权声明:本文为 ...

  3. 属性动画 常用属性及View常用方法

    View类中,常用于属性动画的属性: translationX and translationY: These properties control where the View is located ...

  4. List之Sort使用

    void TestListSort(){ List<string> st = new List<string> (); st.Add ("abcd"); s ...

  5. php-fpm如何优化进程数

    参考链接: php-fpm进程数优化

  6. HDFS文件操作(命令行)

    HDFS是一种分布式文件系统,为MapReduce这种框架下的海量数据分布式处理而设计. Hadoop之HDFS文件操作常有两种方式,一种是命令行方式,即Hadoop提供了一套与Linux文件命令类似 ...

  7. sap.ui.require in SAP UI5 and require in nodejs

    UI5 例如我需要在controller的onShowHello里通过MessageToast弹一个消息显示在UI上, 我需要先定义我自己的controller,该controller extend自 ...

  8. IOS instancetype的使用好处

    instancetype的类型表示上,跟id一样,可以表示任何对象类型 instancetype只能用在返回值类型上,不能像 id 一样用在参数类型上 instancetype 比 id 多一个好处 ...

  9. P1036 选数

    题目描述 已知 nn 个整数 x_1,x_2,…,x_nx1​,x2​,…,xn​,以及11个整数kk(k<nk<n).从nn个整数中任选kk个整数相加,可分别得到一系列的和.例如当n=4 ...

  10. Shell编程学习之Shell编程基础(一)

    这篇随笔将要介绍关于Shell编程的基本知识,这些将会在假设你已经熟悉了Linux系统和命令行的基本知识. 构建基本脚本 你应该了解或熟悉使用Shell命令行了,但是只是使用Shell命令行的命令,有 ...