php imagick 获取psd图层信息
$projectname = 'test';
$im = new Imagick("test.psd");
$num_layers = $im->getNumberImages();
for ($i = 1, $num_layers = $im->getNumberImages(); $i < $num_layers; ++$i) {
$im->setImageIndex($i); //this
$im->setIteratorIndex($i); //or this is kinda redundant
$pagedata = $im->getImagePage();
$pagedata['label'] = $im->getImageProperties("*")['label'];
$allinfo[] =$pagedata;
$im->writeImage($pagedata['label'] . '.png'); //导出所有图层到单独的png文件
}
print_r($allinfo);
exit();
输出数组如下
width是图片宽度
height是图片高度
x和y都是图片相对于容器的位置
label是图层名字 一般用英文 不会乱码
Array
(
[0] => Array
(
[width] => 750
[height] => 1206
[x] => 0
[y] => 0
[label] => bg
)
[1] => Array
(
[width] => 346
[height] => 260
[x] => 292
[y] => 472
[label] => wef1
)
[2] => Array
(
[width] => 269
[height] => 221
[x] => 49
[y] => 40
[label] => wef
)
)
test.psd文件下载地址