PHP将psd转换为jpg,选择图像层 [英] PHP convert psd to jpg, selecting image layers

查看:307
本文介绍了PHP将psd转换为jpg,选择图像层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够选择将.PSD图像中的哪些图层合并到最终的.JPG输出图像中。

I want to be able to select which layers from a .PSD image are merged into the final .JPG output image.

我可以合并所有图层图像包含:

I can merge all of the layers in the image with:

$im = new Imagick('test.psd');
$im->flattenImages();
$im->setImageFormat('jpg');
$im->writeImage('test.jpg');

然而.psd包含大约10个图层,我希望能够指定哪些特定图层应该是合并在一起,以产生最终图像。

However the .psd contains about 10 layers and I want to be able to specify which specific layers should be merged together, to produce the final image.

例如,我想仅合并图层编号3,5和10或名称为RED,GREEN的图层,BLUE

For example I want to merge only layer numbers 3, 5 and 10 or the layers with names "RED", "GREEN", "BLUE"

推荐答案

虽然hsz的答案是正确的,并且是图像非常大的最佳方式,但确实需要您需要提前知道要合并的图层。

Although hsz's answer is correct, and is the best way when the images are very large, it does require you to know ahead of time which layers you want to merge.

您可以使用 setIteratorIndex 访问各个图层并将它们添加到输出图像。

You can do the same thing more programmatically by using setIteratorIndex to access the individual layers and adding them to an output image.

    $imagick = new \Imagick(realpath("../images/LayerTest.psd"));

    $output = new \Imagick();
    $imagick->setIteratorIndex(1);
    $output->addImage($imagick->getimage());

    $imagick->setIteratorIndex(2);
    $output->addImage($imagick->getimage());

    $merged = @$output->flattenimages();
    $merged->setImageFormat('jpg');
    $merged->writeImage('test.jpg');

这篇关于PHP将psd转换为jpg,选择图像层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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