php图片上传旋转压缩方法
用到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图片上传旋转压缩方法的更多相关文章
- PHP实现图片上传并压缩
本文实例讲解了PHP图片上传并压缩的实现方法,分享给大家供大家参考,具体内容如下 使用到三个文件 connect.php:连接数据库 test_upload.php:执行SQL语句 upload_im ...
- php 图片上传的公共方法(按图片宽高缩放或原图)
写的用于图片上传的公共方法类调用方法: $upload_name='pic';$type = 'logo_val';$file_name = 'logo_' . $user_id .create_st ...
- vuejs开发组件分享之H5图片上传、压缩及拍照旋转的问题处理
一.前言 三年.net开发转前端已经四个月了,前端主要用webpack+vue,由于后端转过来的,前端不够系统,希望分享下开发心得与园友一起学习. 图片的上传之前都是用的插件(ajaxupload), ...
- html + js 实现图片上传,压缩,预览及图片压缩后得到Blob对象继续上传问题
先上效果 上传图片后(设置了最多上传3张图片,三张后上传按钮消失) 点击图片放大,可以使用删除和旋转按钮 (旋转功能主要是因为ios手机拍照后上传会有写图片被自动旋转,通过旋转功能可以调正) html ...
- 图片上传前 压缩,base64图片压缩 Exif.js处理ios拍照倒置等问题
曾写过在前端把图片按比例压缩不失真上传服务器的前端和后台,可惜没有及时做总结保留代码,只记得js利用了base64位压缩和Exif.js进行图片处理,还有其中让我头疼的ios拍照上传后会倒置等诸多问题 ...
- vue下实现input实现图片上传,压缩,拼接以及旋转
背景 作为一名前端工作人员,相信大家在开发系统的时候,经常有遇到需要这么一种需求,就是需要为用户保存上传的图片,很多小白遇到这个问题的时候,都会虎躯一震,以为会是一个棘手的问题,当你读完这篇文章的时候 ...
- 微信sdk 图片上传 两种方法 上传一张显示一张 并附带微信图片放大功能和删除功能
html <!--上传图片--> <div class="upload-mod"> <div class="up-box" id= ...
- H5图片上传、压缩
1.注册input file标签的onchange事件: 2.检查图片格式: 3.检查图片大小: 4.压缩图片 5.上传图片至服务器: 前端代码: document.getElementById('i ...
- iOS图片上传及压缩
提到从摄像头/相册获取图片是面向终端用户的,由用户去浏览并选择图片为程序使用.在这里,我们需要过UIImagePickerController类来和用户交互. 使用UIImagePickerContr ...
随机推荐
- MS .NET企业级应用架构设计笔记1(关于业务层)
本文针对<MS .NET企业级应用架构设计>业务层前半部分做了相关笔记并记录了自己的一点想法.对于后半部分的具体模式将在第二次笔记中体现. 关于Layer与Tier Layer一般用来 ...
- 如何修改eclipse的web项目默认浏览器
- mapreduce总结
一.mapreduce简介 MapReduce是一种分布式计算模型,是hadoop的核心组件之一,是Google提出的,主要用于搜索领域,解决海量数据的计算问题. MR有两个阶段组成:Map和Redu ...
- http头部如何对缓存的控制
文章自于我的个人博客 使用缓存的目的就是在于减少计算,IO,网络等时间,可以快速的返回,特别是流量比较大的时候,可以节约很多服务器带宽和压力. 一个请求从缓存的方面来说,有三个过程. 本地检查缓存是否 ...
- SpringCloud的学习记录(7)
这一章节讲zuul的使用. 在我们生成的Demo项目上右键点击New->Module->spring Initializr, 然后next, 填写Group和Artifact等信息, 这里 ...
- IplImage转为Mat的方法
IplImage* S_change_out; Mat matimg; matimg=cvarrToMat(S_change_out);
- form中的action与<url-pattern>的理解
一.<form action="Test/Login" method="post"> 在action中有两种表示方式: 1."/Test/ ...
- 算法练习-Palindrome Number
判断回文整数 来源 https://leetcode.com/problems/palindrome-number/ 要求 判断一个整数是不是回文数,尽量减少内存暂用. 思路 可能的情况: 负数的应当 ...
- Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid b
Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid b ...
- ASP.NET与json对象互转
这两天写这个xml跟json的读写,心累啊,也不是很理解,请大家多指教 首先来个热身菜做一个简单的解析json 在script里写一个简单的弹窗效果 <script> //script里简 ...