使用PHP将cmyk转换为RGB [英] cmyk to rgb using php

查看:274
本文介绍了使用PHP将cmyk转换为RGB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下脚本将图像保存到文件夹中,但是有一个图像显示了此消息由于包含错误,该图像无法显示."

I'm using the following script to save images on a folder, but there is one image that shows this message "the image cannot be displayed because it contains errors".

我认为问题是图像上的cmyk和rgb,但是当在网上搜索某种方式以便使用php将cmyk转换为rgb时,我找不到如何执行此操作的示例.

I think the problem is something called cmyk and rgb on the image, but when searching on the web for a way so convert cmyk to rgb using php I can't find an example of how to do this.

以下是示例之一:

Here is one of example: http://offshootinc.com/blog/2008/10/24/using-the-imagick-class-to-convert-a-cmyk-jpeg-to-rgb/ but I don't undestand how to use that in my case.

图片的链接类似于:www.example.com/attachment?id=2290

The link for the image is something like: www.example.com/attachment?id=2290

脚本如下:

<?php 
$image = 'http://www.dealrush.ie/attachment?id=2290';
$name = 'somename';
$alt = 'somealt';
$saveimage = file_get_contents($image);
file_put_contents("/usr/local/pem/vhosts/155030/webspace/httpdocs/img/$name.jpg", $saveimage);?>

稍后在某些页面中,我将使用类似的方式来显示图像. < img src =" http://www.example.com/img/<?php echo $name?> .jpg" alt ="<?php echo $alt?>" height ="127px"宽度="190px"/

Later in some pages I will use something like this to show the image. <img src="http://www.example.com/img/<?php echo $name?>.jpg" alt="<?php echo $alt?>" height="127px" width="190px"/>

任何有关转换这些图像的帮助将不胜感激 谢谢 丹尼尔

Any help with converting these images will be appreciated Thanks Daniel

推荐答案

我怀疑颜色空间(CMYK或RGB)是您的问题.尽管每个人都应该在网络上使用RGB图像,但浏览器仍会显示CMYK图像而不会引起投诉.

I doubt that the colorspace (CMYK or RGB) is your problem. Although everyone should be using RGB images on the Net, the browsers will still display a CMYK image without complaint.

要将图像从CMYK转换为RGB,需要安装一个想象操作程序,例如ImageMagick,GraphicsMagick或ExactImage.这些中的任何一个都可以执行您想要的操作,但是必须由服务器管理员安装.如果幸运的话,可能已经安装了ImageMagick,在这种情况下,您可以执行以下操作:

To convert the image from CMYK to RGB, you need to have an imagine manipulation program installed, such as ImageMagick, GraphicsMagick, or ExactImage. Any of these can do what you want, but have to be installed by the server admin. If you're luckly, ImageMagick might already be installed, in which case you could do this:

$image= '/path/to/your/file.jpg';
$i = new Imagick($image);
$i->setImageColorspace(Imagick::COLORSPACE_SRGB);
$i->writeImage($image);
$i->destroy();

请注意,ImageMagick是功能最强大的,ExactImage是最快的,而GraphicsMagick是ImageMagick的同类产品,后者速度更快,但功能稍差一些,并且存在一些错误. PHP只能使用ImageMagick,其他必须使用exec函数执行,尽管这不一定是一件坏事,因为它们可能比PHP处理自己的内存和清理要好得多.

Note that ImageMagick is the most powerful, ExactImage is the fastest, and GraphicsMagick is a folk of ImageMagick, which is faster but a little less powerful and has some bugs. Only ImageMagick can be used from PHP, the others have to be executed with the exec function, although that is not necessarily a bad thing as they probably handle their own memory and cleanup much better than PHP would.

这篇关于使用PHP将cmyk转换为RGB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆