Addition if condition for Graphic Magic command

I have the following command:

gm('input.jpg') .crop(500, 500, 10, 10) .write('output.jpg', function (err) { if (err) { console.log(err) } else { console.log('Success') } }) 

I would like to add a condition to it without having to write two different commands, so it would be something like:

 var overlay = true gm('input.jpg') .crop(500, 500, 10, 10) if(overlay == true){ .draw('image Over 0,0 750,750 overlay.jpg') } .write('output.jpg', function (err) { if (err) { console.log(err) } else { console.log('Success') } }) 

I know that the code above will not work, I am looking for an offer for something that will work, without having two different GM commands

+5
source share
1 answer

Unless there is something impressively magical about how the GM library works here, you can break the chain gm().crop().write() into smaller pieces, à la

 var overlay = true; // ... var g = gm('input.jpg').crop(500, 500, 10, 10); if (overlay) { g = g.draw('image Over 0,0 750,750 overlay.jpg'); } g.write('output.jpg', function (err) { if (err) throw err; console.log('Success'); }); 
+4
source

Source: https://habr.com/ru/post/1260836/


All Articles