将图像转换为 php GDImage 对象时的图像质量问题

Issues with image quality when converting image to php GDImage object

我目前正在尝试将图像转换为 PHP 的 gdImage 对象,以便我可以在网站上显示它之前对其进行裁剪和调整大小。

这是用于演示问题的 php 的简化版本。

$src_image = imagecreatefromjpeg('./original.jpg');
imagejpeg($src_image, './copy.jpg', 100);

它只是转换为 php 对象并将其重新写入文件

这是一张正在失去质量的示例图片 https://s4.chorus-mk.thirdlight.com/file/24/VqvaOZDVqqaDrJ_VqtRlVzq4gcw/width=1140/height=1140/format=JPG/fit=stretch/crop=1228x0+4912x4912/rev=1/EV2021BPCP_RM_Members%20Bar_0112.jpg

任何人都可以提出发生这种情况的原因吗?

您的图像包含 ICC 颜色配置文件。你可以看到 ImageMagick 使用:

magick identify -verbose YOURIMAGE

或像这样 exiftool

exiftool YOURIMAGE

ExifTool Version Number         : 12.30
File Name                       : EV2021BPCP_RM_Members Bar_0112.jpg
Directory                       : .
File Size                       : 296 KiB
File Modification Date/Time     : 2022:03:02 15:47:47+00:00
File Access Date/Time           : 2022:03:02 15:50:03+00:00
File Inode Change Date/Time     : 2022:03:02 15:49:37+00:00
File Permissions                : -rw-r--r--
File Type                       : JPEG
File Type Extension             : jpg
MIME Type                       : image/jpeg
JFIF Version                    : 1.01
Resolution Unit                 : inches
X Resolution                    : 300
Y Resolution                    : 300
Profile CMM Type                : Little CMS
Profile Version                 : 2.3.0
Profile Class                   : Display Device Profile
Color Space Data                : RGB
Profile Connection Space        : XYZ
Profile Date Time               : 2008:01:10 15:30:40
Profile File Signature          : acsp
Primary Platform                : Microsoft Corporation
CMM Flags                       : Not Embedded, Independent
Device Manufacturer             : Little CMS
Device Model                    : 
Device Attributes               : Reflective, Glossy, Positive, Color
Rendering Intent                : Perceptual
Connection Space Illuminant     : 0.9642 1 0.82491
Profile Creator                 : Little CMS
Profile ID                      : 0
Device Mfg Desc                 : little cms
Profile Description             : ProPhoto
Device Model Desc               : ProPhoto
Media White Point               : 0.96396 1 0.82414
Red Matrix Column               : 0.79752 0.28799 2e-05
Blue Matrix Column              : 0.03143 0.00012 0.82494
Green Matrix Column             : 0.13525 0.71188 -3e-05
Red Tone Reproduction Curve     : (Binary data 14 bytes, use -b option to extract)
Green Tone Reproduction Curve   : (Binary data 14 bytes, use -b option to extract)
Blue Tone Reproduction Curve    : (Binary data 14 bytes, use -b option to extract)
Chromaticity Channels           : 3
Chromaticity Colorant           : Unknown (0)
Chromaticity Channel 1          : 0.7347 0.2653
Chromaticity Channel 2          : 0.15961 0.84039
Chromaticity Channel 3          : 0.03661 0.00011
Profile Copyright               : Copyright (c) 2008, Sandy McGuffog. Some rights reserved..This work is licensed under the Creative Commons Attribution-Share Alike 3.0 United States License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/us/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.
Media Black Point               : 0 0 0
Image Width                     : 1140
Image Height                    : 1140
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
Image Size                      : 1140x1140
Megapixels                      : 1.3

我建议您使用可以为您保存配置文件的库,例如 ImageMagickvips.