zoukankan      html  css  js  c++  java
  • 移动端上传图片iphone图片旋转以及服务端处理方法

    判断是否需要旋转

        /**
                 *iphone判断图片方向,是否需要旋转图片
                 */
                if(strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone')&&in_array($ext, array('jpg','png','gif','jpeg','jepg'))){
                    $exif =exif_read_data($tmp);
                    switch ($exif['Orientation']){
                        case 6:
                            self::imgturn($tmp,1,$ext);
                            break;
                        case 3:
                            self::imgturn($tmp,1,$ext);
                            self::imgturn($tmp,1,$ext);
                            break;
                        case 8:
                            self::imgturn($tmp,2,$ext);
                            break;
                    }
                }

    一下是php旋转方法

    function imgturn($src, $direction = 1,$ext) {
            switch ($ext) {
                case 'gif' :
                    $img = imagecreatefromgif ( $src );
                    break;
                case 'jepg':
                case 'jpg' :
                case 'jpeg' :
                    $img = imagecreatefromjpeg ( $src );
                    break;
                case 'png' :
                    $img = imagecreatefrompng ( $src );
                    break;
                default :
                    die ( '图片格式错误!' );
                    break;
            }
            $width = imagesx ( $img );
            $height = imagesy ( $img );
            $img2 = imagecreatetruecolor ( $height, $width );
            // 顺时针旋转90度
            if ($direction == 1) {
                for($x = 0; $x < $width; $x ++) {
                    for($y = 0; $y < $height; $y ++) {
                        imagecopy ( $img2, $img, $height - 1 - $y, $x, $x, $y, 1, 1 );
                    }
                }
            } else if ($direction == 2) {
                // 逆时针旋转90度
                for($x = 0; $x < $height; $x ++) {
                    for($y = 0; $y < $width; $y ++) {
                        imagecopy ( $img2, $img, $x, $y, $width - 1 - $y, $x, 1, 1 );
                    }
                }
            }
            switch ($ext) {
                case 'jepg':
                case 'jpg' :
                case "jpeg" :
                    imagejpeg ( $img2, $src, 100 );
                    break;
                
                case "gif" :
                    imagegif ( $img2, $src, 100 );
                    break;
                
                case "png" :
                    imagepng ( $img2, $src, 100 );
                    break;
                
                default :
                    die ( '图片格式错误!' );
                    break;
            }
            imagedestroy ( $img );
            imagedestroy ( $img2 );
        }

  • 相关阅读:
    Sqlserver的Transaction做Rollback的时候要小心(转载)
    注意Sqlserver中使用with(nolock)后实际上还是会加架构锁,只是不对要查询的数据加S锁而已(转载)
    为什么Sql Server的查询有时候第一次执行很慢,第二次,第三次执行就变快了
    Sql Server 中如果使用TransactionScope开启一个分布式事务,使用该事务两个并发的连接会互相死锁吗
    Css中路径data:image/png;base64的用法详解 (转载)
    android获取mp4视频文件总时长和视频宽高<转>
    “Avoid non-default constructors in fragments: use a default constructor plus Fragment#setArguments(Bundle)instead”
    android 除法运算保留小数点
    Directshow 采集音视频数据H264+AAC+rtmp效果还不错
    VS2010中将CString转换为const char*
  • 原文地址:https://www.cnblogs.com/sss-justdDoIt/p/6259339.html
Copyright © 2011-2022 走看看