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 ...
随机推荐
- Visual Studio 2017 安装失败,你们有这样的问题吗?怎么解决
由于发生一个或多个包故障,产品未能安装列出的工作负荷和组件. 工作负荷不完整 使用 JavaScript 的移动开发 (Microsoft.VisualStudio.Workload.WebCross ...
- jQuery中的CSS-DOM操作
html代码 <p style="color:blue;">武汉PHP培训-武汉长乐教育</p> css()方法 $("p").css( ...
- Python常用模块(一)
一.time模块 time模块提供各种操作时间的函数 时间三种格式 1.时间戳 以1970年1月1日 00:00:00开始的秒数 2.本地时间 localtime,表示计算机当前的时间 3.UTC世界 ...
- react-router + redux + react-redux 的例子与分析
一个 react-router + redux + react-redux 的例子与分析 index.js import React from 'react' import ReactDom fr ...
- textarea存起来的数据把空格也存起来
textarea的属性wrap="hard"可以把换行的内容也存起来. <html> <head> <title>这是一个小测试</tit ...
- spring笔记4-事务管理
一.xml配置文件形式 通过转账案例,学习事务管理 1.建立数据库 2.编写entity package huguangqin.com.cnblogs.entity; public class Use ...
- SpringCloud的学习记录(3)
这一章节讲搭建config-server的项目. 在我们生成的Demo项目上右键点击New->Module->spring Initializr, 然后next, 填写Group和Arti ...
- tomcat8.5配置优化
1.应用程序安全&关闭自动部署 默认值: <Host name="localhost" appBase="webapps" unpackWARs= ...
- 谁动了我的I/O?
首先,是信用卡账单欠款0.13美刀~~~然后上亚马逊云查了一下账单. 3M次I/O...(1215133次超额的,2000000次免费的.) 于是监控了一下数据:每秒至少写5次,每秒写300KB,平均 ...
- Element-ui安装与使用(网站快速成型工具)
我之所以将Element归类为Vue.js,其主要原因是Element是(饿了么团队)基于MVVM框架Vue开源出来的一套前端ui组件.我最爱的就是它的布局容器!!! 下面进入正题: 1.Elemen ...