Rumah > php教程 > php手册 > PHP 图片 保持高宽不变压缩之后imagejpeg($source,$file,100) 仍

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

WBOY
Lepaskan: 2016-06-06 19:49:25
asal
954 orang telah melayarinya

图片品质前后对比 : 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>
Salin selepas log masuk
<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>
Salin selepas log masuk
<strong>压缩之后:</strong>
Salin selepas log masuk
<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>
Salin selepas log masuk




<?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]);
Salin selepas log masuk


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


Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Cadangan popular
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan