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

本文探讨了图片在不同压缩比率下品质的变化,特别关注了失真情况及压缩后的文件大小。通过示例代码展示了一种压缩图片的方法,并分析了其对图片质量的影响。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

图片品质前后对比 : 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
  'MimeType' => string 'image/jpeg' (length=10)
  'SectionsFound' => string 'ANY_TAG, IFD0, THUMBNAIL, EXIF' (length=30)
  'COMPUTED' => 
    array (size=7)
      'html' => string 'width="300" height="300"' (length=24)
      'Height' => int 300
      'Width' => int 300
      'IsColor' => int 1
      'ByteOrderMotorola' => int 1
      'Thumbnail.FileType' => int 2
      'Thumbnail.MimeType' => string 'image/jpeg' (length=10)
  'Orientation' => int 1
  'XResolution' => string '72/1' (length=4)
  'YResolution' => string '72/1' (length=4)
  'ResolutionUnit' => int 2
  'Software' => string 'Adobe Photoshop CS Windows' (length=26)
  'DateTime' => string '2013:04:26 10:56:18' (length=19)
  'Exif_IFD_Pointer' => int 164
  'THUMBNAIL' => 
    array (size=6)
      'Compression' => int 6
      'XResolution' => string '72/1' (length=4)
      'YResolution' => string '72/1' (length=4)
      'ResolutionUnit' => int 2
      'JPEGInterchangeFormat' => int 302
      'JPEGInterchangeFormatLength' => int 5519
  'ColorSpace' => int 1
  'ExifImageWidth' => int 300
  'ExifImageLength' => int 300
压缩之后:
array (size=8)
  'FileName' => string '1367000585108300044.jpg' (length=23)
  'FileDateTime' => int 1367029385
  'FileSize' => int 38802
  'FileType' => int 2
  'MimeType' => string 'image/jpeg' (length=10)
  'SectionsFound' => string 'COMMENT' (length=7)
  'COMPUTED' => 
    array (size=4)
      'html' => string 'width="300" height="300"' (length=24)
      'Height' => int 300
      'Width' => int 300
      'IsColor' => int 1
  'COMMENT' => 
    array (size=1)
      0 => string '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%。


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值