Added Text Overlay module (#917)

This commit is contained in:
aashna27
2019-03-26 01:28:02 +05:30
committed by Jeffrey Warren
parent 488bbd86da
commit 60cfcb4d30
5 changed files with 134 additions and 0 deletions

View File

@@ -34,6 +34,7 @@ module.exports = {
'resize': require('./modules/Resize'),
'rotate': require('./modules/Rotate'),
'saturation': require('./modules/Saturation'),
'text-overlay': require('./modules/TextOverlay'),
'threshold': require('./modules/Threshold'),
'tint': require('./modules/Tint'),
'color-temperature': require('./modules/ColorTemperature')

View File

@@ -0,0 +1,51 @@
module.exports = function TextOverlay(options,UI) {
var output;
function draw(input, callback, progressObj) {
progressObj.stop(true);
progressObj.overrideFlag = true;
var step = this;
if (!options.step.inBrowser) { // This module is only for browser
this.output = input;
callback();
}
else{
var priorStep = this.getStep(-1); // get the previous step to add text onto it.
function extraManipulation(pixels) {
//if (options.step.inBrowser)
pixels = require('./TextOverlay')(pixels, options,priorStep);
return pixels
}
function output(image, datauri, mimetype) {
// This output is accesible by Image Sequencer
step.output = { src: datauri, format: mimetype };
}
return require('../_nomodule/PixelManipulation.js')(input, {
output: output,
extraManipulation: extraManipulation,
format: input.format,
image: options.image,
inBrowser: options.inBrowser,
callback: callback
});
}
}
return {
options: options,
draw: draw,
output: output,
UI: UI
}
}

View File

@@ -0,0 +1,25 @@
module.exports = exports = function(pixels, options,priorstep){
var defaults = require('./../../util/getDefaults.js')(require('./info.json'));
options.text = options.text || defaults.text;
options.x = options.x || defaults.x;
options.y = options.y || defaults.y;
options.font = options.font || defaults.font;
options.color = options.color || defaults.color;
options.size = options.size || defaults.size;
var img = $(priorstep.imgElement);
var canvas = document.createElement("canvas");
canvas.width = pixels.shape[0]; //img.width();
canvas.height = pixels.shape[1]; //img.height();
var ctx = canvas.getContext('2d');
ctx.drawImage(img[0], 0, 0);
ctx.fillStyle = options.color;
ctx.font = options.size +"px " + options.font;
ctx.fillText(options.text, options.x, options.y);
var myImageData = ctx.getImageData(0,0,canvas.width,canvas.height);
pixels.data = myImageData.data
return pixels;
}

View File

@@ -0,0 +1,4 @@
module.exports = [
require('./Module'),
require('./info.json')
]

View File

@@ -0,0 +1,53 @@
{
"name": "Text-Overlay",
"description": "Overlay text on image.",
"inputs": {
"text": {
"type": "string",
"desc": "Enter the text to overlay.",
"default": "Lorem ipsum"
},
"x": {
"type": "integer",
"desc": "Starting text horizontal position.",
"default": "20"
},
"y": {
"type": "integer",
"desc": "Starting text vertical position.",
"default": "20"
},
"font": {
"type": "select",
"desc": "Select the font style.",
"default": "serif",
"values": [
"serif",
"arial",
"times",
"courier",
"Montserrat"
]
},
"color": {
"type": "select",
"desc": "Select the text color.",
"default": "black",
"values": [
"black",
"blue",
"green",
"red",
"white",
"pink",
"orange"
]
},
"size": {
"type" : "integer",
"desc": "Enter the font size in pixels.",
"default": "12"
}
},
"only": "browser"
}