3

Hi If anyone can help would be great. I am trying to create a mosaic of 25 images all together, and apply some effects on top. So I am starting with creating a mask.png which has rounded corners. Then with a for cycle for each tile I would like to apply this mask and colour on top with opacity: Here is my code:

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');
})

Can some one help me to understand why is not working, maybe I am doing something wrong?

Andrea
  • 11,801
  • 17
  • 65
  • 72
Alex
  • 1,571
  • 3
  • 13
  • 16
  • 1
    Not sure about the `node.js` side of things, but maybe your command goes through a shell which interprets the parentheses rather than letting **ImageMagick** see them, so maybe you need double quotes around your `rgba()` specifier, making something like `xc:"rgb(255,255,0,0.5)"` – Mark Setchell Nov 16 '16 at 15:39

0 Answers0