嗨如果有人可以提供帮助就会很棒。我试图创建一个包含25个图像的马赛克,并在顶部应用一些效果。所以我开始创建一个有圆角的mask.png。然后对每个瓷砖使用一个for循环,我想在不透明度的顶部应用这个蒙版和颜色: 这是我的代码:
var gm = require('gm');
var path = require('path');
gm('xc:none')
.in('-size', '100x100')
.in('-draw',"roundrectangle 0,0,99,99,12,12")
.write('mask.png', function(err){
if(err) console.log(err);
console.log('mask done');
})
var img = gm();
img.in('-background', 'black')
var tile = 100;
for(var i=0;i<=4;i++){
for(var h=0;h<=4;h++){
//-=TILE IMAGE=-
img.in('-page', '+'+((tile*i)+(i*3))+'+'+((tile*h)+(h*3)))
img.in('image1.jpg');
img.in('-resize', tile+'x'+tile)
img.in('-density', tile+'x'+tile)
//-=COLOR=-
img.in('-page', '+'+((tile*i)+(i*3))+'+'+((tile*h)+(h*3)))
img.in('-size', (tile)+'x'+(tile))
//THIS IS NOT WORKING AS EXPECTED, OPACITY IS NOT APPLIED
img.in('xc:rgba('+(255)+','+(0)+','+(0)+', 0.5)')
img.in('-resize', tile+'x'+tile)
//-=MASK=-
//THIS IS NOT WORKING AS EXPECTED, THE CORNERS ARE WHITE
//SEEMS THAT THE
img.in('-compose', 'copyopacity')
img.in('mask.png')
img.in('-resize', tile+'x'+tile)
}
}
img.mosaic()
img.write('test.png', function(err){
if(err) console.log(err);
console.log('image done');
})
有人可以帮助我理解为什么不工作,也许我做错了什么?