Home > php教程 > php手册 > body text

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

WBOY
Release: 2016-06-06 19:49:25
Original
930 people have browsed it

图片品质前后对比 : 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>
Copy after login
<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>
Copy after login
<strong>压缩之后:</strong>
Copy after login
<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>
Copy after login




<?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]);
Copy after login


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


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template