您现在的位置是:首页 > 学无止境
用PHP将CMYK格式的JPG文件转为RGB格式
上次说到,CMYK格式的JPG用IE6浏览时无法显示,解决方法是用PS之类的软件转成RGB。但对于网站来说,用户并不知道这么解决,所以还是要程序想办法解决了。解决方法是用imagick或者imagemagick来处理图片,imagick代码如下:
$filePath = ...
$filePath = ...
上次说到,CMYK格式的JPG用IE6浏览时无法显示,解决方法是用PS之类的软件转成RGB。但对于网站来说,用户并不知道这么解决,所以还是要程序想办法解决了。解决方法是用imagick或者imagemagick来处理图片,imagick代码如下:
<?php
$filePath = '/path/to/your/file.jpg';
$i = new Imagick($filePath);
$cs = $i->getImageColorspace();
if ($cs == Imagick::COLORSPACE_CMYK) {
print "Image is CMYK<br/>n";
?>
CMYK Image:<br/>;
<img src="<?php echo $filePath ?>"/>
<br/><br/>
<?php
$i->setImageColorspace(Imagick::COLORSPACE_SRGB);
$i->setImageFormat('jpeg');
$cs = $i->getImageColorspace();
if ($cs != Imagick::COLORSPACE_CMYK) {
print "Image is no longer CMYK<br/>n";
// write it to a temp file
$filePath = '/path/to/temp/file.jpg';
$i->writeImage($filePath);
}
} else {
print "Image is not CMYK<br/>n";
}
if ($cs == Imagick::COLORSPACE_SRGB ||
$cs == Imagick::COLORSPACE_RGB){
print "Image is RGB<br/>n";
}
?>
RGB Image:<br/>
<img src="<?php echo $filePath ?>"/>;
<?php
$i->clear();
$i->destroy();
$i = null;上一篇:开源分词程序
下一篇:Web开发中需要了解的东西
文章评论
- 登录后评论
点击排行
-
php-fpm安装、配置与优化
转载自:https://www.zybuluo.com/phper/note/89081 1、php中...
-
centos下postgresql的安装与配置
一、安装(以root身份进行)1、检出最新的postgresql的yum配置从ht...
-
Mysql的大小写敏感性
MYSQL在默认的情况下查询是不区分大小写的,例如:CREATE TABLE...
-
关于URL编码
转载自:http://www.ruanyifeng.com/blog/2010/02/url_encoding....
-
header中的Cache-control
网页的缓存是由HTTP消息头中的“Cache-control”来控制的,常见的...