Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// callback.
callback,
// error handler.
errorHandler;
if (callbackOrHandlers !== undefined) {
if (CHECK_IS_DATA(callbackOrHandlers) !== true) {
callback = callbackOrHandlers;
} else {
callback = callbackOrHandlers.success;
errorHandler = callbackOrHandlers.error;
}
}
imagemagick.convert(params, function(error) {
var
// error msg
errorMsg;
if (error !== TO_DELETE) {
errorMsg = error.toString();
if (errorHandler !== undefined) {
errorHandler(errorMsg);
} else {
console.log(CONSOLE_RED('[UPPERCASE.IO-IMAGEMAGICK_CONVERT] ERROR: ' + errorMsg));
}
} else {
// callback.
callback,
// error handler.
errorHandler;
if (callbackOrHandlers !== undefined) {
if (CHECK_IS_DATA(callbackOrHandlers) !== true) {
callback = callbackOrHandlers;
} else {
callback = callbackOrHandlers.success;
errorHandler = callbackOrHandlers.error;
}
}
imagemagick.convert(params, function(error) {
var
// error msg
errorMsg;
if (error !== TO_DELETE) {
errorMsg = error.toString();
if (errorHandler !== undefined) {
errorHandler(errorMsg);
} else {
console.log(CONSOLE_RED('[UPPERCASE-IMAGEMAGICK_CONVERT] ERROR: ' + errorMsg));
}
} else {
// callback.
callback,
// error handler.
errorHandler;
if (callbackOrHandlers !== undefined) {
if (CHECK_IS_DATA(callbackOrHandlers) !== true) {
callback = callbackOrHandlers;
} else {
callback = callbackOrHandlers.success;
errorHandler = callbackOrHandlers.error;
}
}
imagemagick.convert(params, function(error) {
var
// error msg
errorMsg;
if (error !== TO_DELETE) {
errorMsg = error.toString();
if (errorHandler !== undefined) {
errorHandler(errorMsg);
} else {
SHOW_ERROR('[UPPERCASE-IMAGEMAGICK_CONVERT] ERROR: ' + errorMsg);
}
} else {
// callback.
callback,
// error handler.
errorHandler;
if (callbackOrHandlers !== undefined) {
if (CHECK_IS_DATA(callbackOrHandlers) !== true) {
callback = callbackOrHandlers;
} else {
callback = callbackOrHandlers.success;
errorHandler = callbackOrHandlers.error;
}
}
imagemagick.convert(params, function(error) {
var
// error msg
errorMsg;
if (error !== TO_DELETE) {
errorMsg = error.toString();
if (errorHandler !== undefined) {
errorHandler(errorMsg);
} else {
SHOW_ERROR('[UPPERCASE-IMAGEMAGICK_CONVERT] ERROR: ' + errorMsg);
}
} else {
tasks.push(function(cb) {
// invoke 'convert'
im.convert(convertArgs, function(err, stdout, stderr) {
if(err) return cb(err);
// run identify in the styled image
im.identify(styleFilePath, function(err, atts) {
if(err) return cb(err);
finishConversion(styleFilePath, atts, cb);
});
});
}); // tasks.push
} else {
return new Promise(function (res, rej) {
im.convert(params, (err) => {
if (err) {
console.log(`Error${err}`);
rej(err);
} else {
res('operation completed successfully');
}
});
});
}
im.identify(source, function (err, imageData) {
if (err)
throw new Error('Image-Watermark::embedWatermark : Unable to process image file : ' + err);
var retObj = _parseOptions(imageData, source, options);
im.convert(retObj.args, function(err, stdout) {
if (err)
console.log('Image-Watermark::embedWatermark : Error in applying watermark : ' + err);
else
console.log('Image-Watermark::embedWatermark : Successfully applied watermark. Please check it at :\n ' + retObj.outputPath);
});
});
}
function autoOrient(sourceImagePath, targetPath, callback) {
if (logger.debug) {
logger.debug('Auto-orienting `' + sourceImagePath + '\' into `' + targetPath + '\'');
}
magick.convert([sourceImagePath, '-auto-orient', targetPath], function (err, stdout) {
if (err) {
return callback(err, undefined);
}
if (logger.debug) {
logger.debug('stdout:', stdout);
}
callback(undefined, targetPath);
});
}
function convert(sourceImagePath, targetPath, params, callback) {
const angle = params.angle || '0';
const scale = params.scale || '1';
const geometry = params.geometry || '100x100+0+0';
magick.convert([sourceImagePath, '-rotate', angle, '-resize', parseFloat(scale * 100) + '%', '-crop', geometry, targetPath], err => callback(err, targetPath));
}
function scale(sourceImagePath, targetPath, width, height, fn) {
if (logger.debug) {
logger.debug('Scaling `' + sourceImagePath + '\' to ' + width + 'x' + height + ' into `' + targetPath + '\'');
}
magick.convert([sourceImagePath, '-quality', '75', '-scale', width + '!x' + height + '!', targetPath], function (err, stdout) {
if (err) {
return fn(err, undefined);
}
if (logger.debug) {
logger.debug('stdout:', stdout);
}
fn(undefined, targetPath);
});
}