问题描述
我使用CodeIgniter 1.7开发了一个照片共享社区网站。成员上传的照片会自动调整为多种格式,我使用CodeIgniter Image Manipulation类。这个类内置在框架中,基本上是一个包含多个图像处理库(如GD,GD2,ImageMagick和NETPBM)的包装器。在我的主机上,我只能使用GD2,所以这就是这个问题的地方。
我的问题。以下是我网站上调整大小的照片示例。请注意,原始图片非常大,宽度超过3000像素:
更新2 :我很震惊。在一个好的方式。我花了很多痛苦来安装ImageMagick但切换到它(这是一个问题设置'imagemagick'作为要使用的代码Igniter图像处理类,测试图像的结果如下:
ImageMagick的调整大小是按照预期做的,颜色保留,锐度存在。是的,我禁用了自定义锐化程序,因为它不再需要由于ImageMagick。 ,这个过程是更快,更少的内存饿了。这里又有一个很大的部分:我不能解释它,但我绝对没有什么可以告诉ImageMagick使用一个特定的颜色配置文件,这是由用户@Alix建议。在我的到目前为止,它看起来像颜色信息被尊重有或没有一个嵌入的配置文件输出只是一个较小的输入版本。ImageMagick是真的聪明还是我梦想?
我已经设法进一步测试这与Imagick:
图片的左半部分使用Imagick处理,颜色配置文件,右半部分没有相关联的颜色配置文件,如果使用Imagick或GD处理,则显示完全相同;这里是我使用的代码:
header('Content-type:image / jpeg');
$ image = new Imagick('/ path / to / DSC07275.jpg');
if(($ srgb = file_get_contents('http://www.color.org/sRGB_IEC61966-2-1_no_black_scaling.icc'))!== false)
{
$ image-> profileImage('icc',$ srgb);
$ image-> setImageColorSpace(Imagick :: COLORSPACE_SRGB);
}
$ image-> thumbnailImage(1024,0);
echo $ image;
以下是几个sRGB在color.org网站上:
在我看来,第三个个人资料产生最生动的结果,除了我不知道如何做出明确的选择。
EDIT :显然,Imagick附带了一个捆绑的sRGB配置文件,因此您不需要下载图像颜色联盟网站,以下代码应该处理所有方案:
header('Content-type:image / jpeg') ;
$ image = new Imagick('/ path / to / DSC07275.jpg');
$ version = $ image-> getVersion();
$ profile ='http://www.color.org/sRGB_IEC61966-2-1_no_black_scaling.icc';
if((is_array($ version)=== true)&&(array_key_exists('versionString',$ version)=== true))
{
$ version = preg_replace('〜ImageMagick([^ - ] *)。*〜','$ 1',$ version ['versionString']);
if(is_file(sprintf('/ usr / share / ImageMagick-%s / config / sRGB.icm',$ version))=== true)
{
$ profile = sprintf('/ usr / share / ImageMagick-%s / config / sRGB.icm',$ version);
}
}
if(($ srgb = file_get_contents($ profile))!== false)
{
$ image-> profileImage ('icc',$ srgb);
$ image-> setImageColorSpace(Imagick :: COLORSPACE_SRGB);
}
$ image-> thumbnailImage(1024,0);
echo $ image;
I have developed a photo sharing community site using CodeIgniter 1.7. Photos that are uploaded by members are automatically resized in a number of formats, for which I use the CodeIgniter Image Manipulation class. This class is built into the framework and basically a wrapper around multiple image manipulation libraries, such as GD, GD2, ImageMagick, and NETPBM. On my host, I can only make use of GD2, so that's where this question will be about.
On to my problem. Here is an example of a resized photo on my site. Note that the original was very large, over 3000px wide:
http://www.jungledragon.com/image/195/female_impala_close-up.html
Now, look at that same image, also resized, just a bit larger at Flickr:
http://www.flickr.com/photos/fledder/3763538865/in/set-72157621744113979
See the dramatic difference? I'm trying to bridge that huge gap. The first thing I did was to apply a sharpen filter to the images. You can see the result here:
Although still not perfect, it at least approaches the sharpness level of the Flickr image. The remaining problem is that the colors are washed away, as if their saturation is decreased. This happens before the sharpening filter already, so it must be in GD2.
This issue is vitally important to me, but I don't know where to look. I've found some .NET threads talking about chroma sub sampling but I don't know what to do with that information in my setup. I'm looking for any solution that works within the constraints of my setup.
Update: Hereby the original file, exactly as I uploaded it both to my site and Flickr:
http://www.jungledragon.com/img/DSC07275.jpg
Update 2: I'm shocked. In a good way. It took me a lot of pain to install ImageMagick but after switching to it (which was a matter of setting 'imagemagick' as the library to use at the Code Igniter image manipulation class, the result of the test image is as follow:
ImageMagick's resizing is doing it exactly as intended. The colors are preserved, and the sharpness is there. Yes, I disabled my custom sharpening routine since it is no longer needed due to ImageMagick. On top of that, the process is a lot faster and less memory hungry too. And here comes another great part: I cannot explain it, but I did absolutely nothing to tell ImageMagick to use a specific color profile, which was suggested by user @Alix. In my testing so far it looks like the color information is respected with or without an embedded profile. The output simply is a smaller version of the input. Is ImageMagick really that smart or am I dreaming?
I've managed to further test this with Imagick:
The left half of the image was processed with Imagick and the sRGB_IEC61966-2-1_no_black_scaling.icc
color profile, the right half has no color profile associated and shows exactly the same if processed with Imagick or GD; here is the code I used:
header('Content-type: image/jpeg');
$image = new Imagick('/path/to/DSC07275.jpg');
if (($srgb = file_get_contents('http://www.color.org/sRGB_IEC61966-2-1_no_black_scaling.icc')) !== false)
{
$image->profileImage('icc', $srgb);
$image->setImageColorSpace(Imagick::COLORSPACE_SRGB);
}
$image->thumbnailImage(1024, 0);
echo $image;
Here is a comparison of the several sRGB profiles available on the color.org website:
It seems to me that the third profile produces the most vivid results, other than that I have no idea how one would make a definitive choice.
EDIT: Apparently, Imagick comes with a bundled sRGB profile, so you don't need to download the one from the Image Color Consortium website, the following code should handle all scenarios:
header('Content-type: image/jpeg');
$image = new Imagick('/path/to/DSC07275.jpg');
$version = $image->getVersion();
$profile = 'http://www.color.org/sRGB_IEC61966-2-1_no_black_scaling.icc';
if ((is_array($version) === true) && (array_key_exists('versionString', $version) === true))
{
$version = preg_replace('~ImageMagick ([^-]*).*~', '$1', $version['versionString']);
if (is_file(sprintf('/usr/share/ImageMagick-%s/config/sRGB.icm', $version)) === true)
{
$profile = sprintf('/usr/share/ImageMagick-%s/config/sRGB.icm', $version);
}
}
if (($srgb = file_get_contents($profile)) !== false)
{
$image->profileImage('icc', $srgb);
$image->setImageColorSpace(Imagick::COLORSPACE_SRGB);
}
$image->thumbnailImage(1024, 0);
echo $image;
这篇关于如何在调整图像大小后停止GD2洗掉颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!