首页 > php教程 > php手册 > 正文

PHP 图片 保持高宽不变压缩之后imagejpeg($source,$file,100) 仍

WBOY
发布: 2016-06-06 19:49:25
原创
929 人浏览过

图片品质前后对比 : var_dump(exif_read_data($img));查看 ,严重失真压缩比为 50%。 压缩前: array (size=18) 'FileName' = string '1367000585017724053.JPG' (length=23) 'FileDateTime' = int 1367029384 'FileSize' = int 67872 'FileType' = int 2 '

图片品质前后对比 : var_dump(exif_read_data($img));查看 ,严重失真压缩比为 50%。


<strong>压缩前:</strong>
登录后复制
<strong>array</strong> <em>(size=18)</em>
  'FileName' <span>=></span> <small>string</small> <span>'1367000585017724053.JPG'</span> <em>(length=23)</em>
  'FileDateTime' <span>=></span> <small>int</small> <span>1367029384</span>
  'FileSize' <span>=></span> <small>int</small> <span>67872</span>
  'FileType' <span>=></span> <small>int</small> <span>2</span>
  'MimeType' <span>=></span> <small>string</small> <span>'image/jpeg'</span> <em>(length=10)</em>
  'divsFound' <span>=></span> <small>string</small> <span>'ANY_TAG, IFD0, THUMBNAIL, EXIF'</span> <em>(length=30)</em>
  'COMPUTED' <span>=></span> 
    <strong>array</strong> <em>(size=7)</em>
      'html' <span>=></span> <small>string</small> <span>'width="300" height="300"'</span> <em>(length=24)</em>
      'Height' <span>=></span> <small>int</small> <span>300</span>
      'Width' <span>=></span> <small>int</small> <span>300</span>
      'IsColor' <span>=></span> <small>int</small> <span>1</span>
      'ByteOrderMotorola' <span>=></span> <small>int</small> <span>1</span>
      'Thumbnail.FileType' <span>=></span> <small>int</small> <span>2</span>
      'Thumbnail.MimeType' <span>=></span> <small>string</small> <span>'image/jpeg'</span> <em>(length=10)</em>
  'Orientation' <span>=></span> <small>int</small> <span>1</span>
  'XResolution' <span>=></span> <small>string</small> <span>'72/1'</span> <em>(length=4)</em>
  'YResolution' <span>=></span> <small>string</small> <span>'72/1'</span> <em>(length=4)</em>
  'ResolutionUnit' <span>=></span> <small>int</small> <span>2</span>
  'Software' <span>=></span> <small>string</small> <span>'Adobe Photoshop CS Windows'</span> <em>(length=26)</em>
  'DateTime' <span>=></span> <small>string</small> <span>'2013:04:26 10:56:18'</span> <em>(length=19)</em>
  'Exif_IFD_Pointer' <span>=></span> <small>int</small> <span>164</span>
  'THUMBNAIL' <span>=></span> 
    <strong>array</strong> <em>(size=6)</em>
      'Compression' <span>=></span> <small>int</small> <span>6</span>
      'XResolution' <span>=></span> <small>string</small> <span>'72/1'</span> <em>(length=4)</em>
      'YResolution' <span>=></span> <small>string</small> <span>'72/1'</span> <em>(length=4)</em>
      'ResolutionUnit' <span>=></span> <small>int</small> <span>2</span>
      'JPEGInterchangeFormat' <span>=></span> <small>int</small> <span>302</span>
      'JPEGInterchangeFormatLength' <span>=></span> <small>int</small> <span>5519</span>
  'ColorSpace' <span>=></span> <small>int</small> <span>1</span>
  'ExifImageWidth' <span>=></span> <small>int</small> <span>300</span>
  'ExifImageLength' <span>=></span> <small>int</small> <span>300</span>
登录后复制
<strong>压缩之后:</strong>
登录后复制
<strong>array</strong> <em>(size=8)</em>
  'FileName' <span>=></span> <small>string</small> <span>'1367000585108300044.jpg'</span> <em>(length=23)</em>
  'FileDateTime' <span>=></span> <small>int</small> <span>1367029385</span>
  'FileSize' <span>=></span> <small>int</small> <span>38802</span>
  'FileType' <span>=></span> <small>int</small> <span>2</span>
  'MimeType' <span>=></span> <small>string</small> <span>'image/jpeg'</span> <em>(length=10)</em>
  'divsFound' <span>=></span> <small>string</small> <span>'COMMENT'</span> <em>(length=7)</em>
  'COMPUTED' <span>=></span> 
    <strong>array</strong> <em>(size=4)</em>
      'html' <span>=></span> <small>string</small> <span>'width="300" height="300"'</span> <em>(length=24)</em>
      'Height' <span>=></span> <small>int</small> <span>300</span>
      'Width' <span>=></span> <small>int</small> <span>300</span>
      'IsColor' <span>=></span> <small>int</small> <span>1</span>
  'COMMENT' <span>=></span> 
    <strong>array</strong> <em>(size=1)</em>
      0 <span>=></span> <small>string</small> <span>'CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality = 100
'</span> <em>(length=58)</em>
登录后复制




<?php $img_thumb  = imagecreatetruecolor($thumb_width, $thumb_height);
$bgcolor = trim($bgcolor,"#");
sscanf($bgcolor, "%2x%2x%2x", $red, $green, $blue);
$clr = imagecolorallocate($img_thumb, $red, $green, $blue);
imagefilledrectangle($img_thumb, 0, 0, $thumb_width, $thumb_height, $clr);
imagecopyresampled($img_thumb, $img_org, $dst_x, $dst_y, 0, 0, $lessen_width, $lessen_height, $org_info[0], $org_info[1]);
登录后复制


图片只要经过那个函数的压缩,仍旧是失真的,图片文件大小压缩率为 50%。


相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板