1. 程式人生 > >PHP 圖片 保持高寬不變壓縮之後imagejpeg($source,$file,100) 仍舊失真!

PHP 圖片 保持高寬不變壓縮之後imagejpeg($source,$file,100) 仍舊失真!

圖片品質前後對比 : var_dump(exif_read_data($img));檢視 ,嚴重失真壓縮比為 50%。

壓縮前:
array (size=18)
  'FileName' =>  '1367000585017724053.JPG' (length=23)
  'FileDateTime' =>  1367029384
  'FileSize' =>  67872
  'FileType' =>  2
  'MimeType' =>  'image/jpeg' (length=10)
  'SectionsFound' =>  'ANY_TAG, IFD0, THUMBNAIL, EXIF'
(length=30) 'COMPUTED' => array (size=7) 'html' => 'width="300" height="300"' (length=24) 'Height' => 300 'Width' => 300 'IsColor' => 1 'ByteOrderMotorola' => 1 'Thumbnail.FileType' => 2 'Thumbnail.MimeType' => 'image/jpeg' (length=10)
'Orientation' => 1 'XResolution' => '72/1' (length=4) 'YResolution' => '72/1' (length=4) 'ResolutionUnit' => 2 'Software' => 'Adobe Photoshop CS Windows' (length=26) 'DateTime' => '2013:04:26 10:56:18' (length=19) 'Exif_IFD_Pointer' => 164 'THUMBNAIL' => array
(size=6) 'Compression' => 6 'XResolution' => '72/1' (length=4) 'YResolution' => '72/1' (length=4) 'ResolutionUnit' => 2 'JPEGInterchangeFormat' => 302 'JPEGInterchangeFormatLength' => 5519 'ColorSpace' => 1 'ExifImageWidth' => 300 'ExifImageLength' => 300
壓縮之後:
array (size=8)
  'FileName' =>  '1367000585108300044.jpg' (length=23)
  'FileDateTime' =>  1367029385
  'FileSize' =>  38802
  'FileType' =>  2
  'MimeType' =>  'image/jpeg' (length=10)
  'SectionsFound' =>  'COMMENT' (length=7)
  'COMPUTED' => 
    array (size=4)
      'html' =>  'width="300" height="300"' (length=24)
      'Height' =>  300
      'Width' =>  300
      'IsColor' =>  1
  'COMMENT' => 
    array (size=1)
      0 =>  'CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality = 100
' (length=58)
<?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%。