用到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. Chrome调式技巧

    1. 使用alert()调试 2.  console 基本输出 console.log("打印字符串"); console.error("我是个错误"); co ...

  2. 连接Mysql时出现java.math.BigInteger cannot be cast to java.lang.Long问题

    今天遇见这样一个坑.在连接数据库进行查询数据时,大家可能会遇见这样一个问题:java.math.BigInteger cannot be cast to java.lang.Long,然后去检查代码中 ...

  3. Spring课程 Spring入门篇 1-2Spring简介

    课程链接: 1 Spring是什么? 2 为什么是Spring 3 Spring的作用: 4 适用范围 1 Spring是什么? a 开源框架 b 轻量级的控制反转(Ioc)和面向切面编程(AOP)的 ...

  4. jQuery属性选择器中加变量

    $(function () { $('#bkhandle').on('click','#bkdel',function () { $.ajax( { url:"{% url 'bkdel' ...

  5. SpringBoot常用应用程序属性

    参考地址: https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.h ...

  6. 开源时序服务器influxdb使用

    文档 https://influxdb.com/docs/v0.9/introduction/overview.html 配置文件 /etc/opt/influxdb/influxdb.conf re ...

  7. API:Sign签名的执行流程

    Sign签名存在目的:为了防止不法分子修改参数数据,进而攻击服务器,导致数据泄露或从中获得利益    例如:一个接口是用户把积分转帐给他的朋友,修改后,变为转帐到攻击者的帐户,这样,攻击者就能得到利益 ...

  8. 257. Binary Tree Paths (dfs recurive & stack)

    Given a binary tree, return all root-to-leaf paths. Note: A leaf is a node with no children. Example ...

  9. InnoDB锁演示

    create table t1( c1 int(10) unsigned not null default '0', c2 int(10) unsigned not null default '0', ...

  10. hdu-1247 Hat’s Words---字典树模板

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1247 题目大意: 给出一些单词,以EOF结束,看其中哪一个单词可以由其他两个单词组成,将其输出 解题 ...