用PHP将CMYK格式的JPG文件转为RGB格式

来源:互联网 发布:imac删除windows系统 编辑:程序博客网 时间:2024/05/22 01:28

上次说到,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;

原创粉丝点击