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,EAAiB,QAAS,SAAS,EAAW,IAClF,MAAM,GAAa,SAAU,GAC1B,EAAS,MAAM,EACnB,IACW,kBAAR,EACP,YAAY,GACP,OAAO,EAAY,MAAO,EAAY,OAAQ,KAC9C,aAAa,EAAY,QAAS,EAAY,MAAO,EAAY,QACjE,aAAa,EAAiB,KAAM,EAAiB,QAAS,SAAS,EAAW,IAClF,MAAM,GAAa,SAAU,GAC1B,EAAS,MAAM,EACnB,IAEJ,EAAS,IAAI,MAAM,sBAAsB,EAEjD,IAGQ,QAAR,EAQI,EAAY,OAAS,EAAY,OACjC,YAAY,GACP,OAAO,EAAY,MAAO,EAAY,OAAQ,KAC9C,aAAa,EAAY,QAAS,EAAY,MAAO,EAAY,QACjE,MAAM,GAAa,SAAU,GAC1B,QAAQ,IAAI,GAAK,gBAAkB,GACnC,EAAS,MAAM,EACnB,IAEJ,EAAS,IAAI,MAAM,0BAA0B,EAAY,MAAM,MAAM,EAAY,SAAS,GAG9F,EAAS,IAAI,MAAM,sBAAsB,EAEjD,IAEA,EAAS,aAAa,EAAO,aAAa,KAAK,oBAAoB,EAAY,aAAa,GAAM,EAE1G,EAEA,OAAO,QAAQ,MAAQ","file":"/npm/imagemagick-dynamic-watermark@3.1.0/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/imagemagick-dynamic-watermark@3.1.0/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","/**\n * imagemagick-dynamic-watermark\n *\n *\n * Copyright (c) 2017 Sadegh Mohebbi\n * Licensed under the MIT license.\n */\n\n/**\n * ImageMagick Dynamic Watermark is npm watermark module to add watermark over cropped or original image.\n * @param  {options}\n * @return {callback}\n */\n\nconst gm = require('gm');\nconst imageMagick = gm.subClass({imageMagick: true});\n\nimageMagick.prototype.cropOnAspect = function(gravity, width, height) {\n    return this.gravity(gravity)\n        .crop(width, height);\n}\n\nimageMagick.prototype.overlayImage = function(logo, gravity, resize) {\n    return this.gravity(gravity)\n        .out('(', logo, ' ', '-resize', resize, ')')\n        .out('-composite');\n}\n\nfunction resizeTo(width, height) {\n    return width + 'x' + height + '>';\n}\n\nvar apply = function (options, callback) {\n\n    var source = options.source;   // Source file path\n    var destination = options.destination; // Destination file path\n\n    var type = options.type;//watermark, crop, crop_watermark\n    \n    if (source && destination && type) {\n        imageMagick(source).size(function (err, size) {\n            if (err) callback(err, false);\n\n            var watermark_params = options.watermark;\n            var crop_params = options.crop;\n\n            /* \n            resize watermark logo by keeping aspect ratio or resize it to \n            provided percent of source image or fixed size\n             */\n            var logoWidth, logoHeight;\n            if (watermark_params && watermark_params.logo) {\n                imageMagick(watermark_params.logo).size(function (err, logoSize) {\n                    if (err) callback(err, false);\n\n                    if (watermark_params.logoWidthPercent && watermark_params.logoHeightPercent) {\n                        logoWidth = watermark_params.logoWidthPercent * size.width;\n                        logoHeight = watermark_params.logoHeightPercent * size.height;\n                    } else if (watermark_params.logoWidthPercent) {\n                        logoWidth = watermark_params.logoWidthPercent * size.width;\n                        //calculate logoHeight with keeping aspect ratio\n                        logoHeight = (logoSize.height * logoWidth) / logoSize.width;\n                    } else if (watermark_params.logoHeightPercent) {\n                        logoHeight = watermark_params.logoHeightPercent * size.height;\n                        //calculate logo with keeping aspect ratio\n                        logoWidth = (logoSize.width * logoHeight) / logoSize.height;\n                    } else {\n                        if (watermark_params.logoWidth && watermark_params.logoHeight) {\n                            logoWidth = watermark_params.logoWidth;\n                            logoHeight = watermark_params.logoHeight;\n                        } else {\n                            callback(new Error(\"logo logoWidth x logoHeight is \"+watermark_params.logoWidth+\" x \"+watermark_params.logoHeight), false);\n                        }\n                    }\n    \n                    if (type == \"watermark\") {\n                        /*\n                        watermark: {\n                            logo: String -> logo file path\n                            gravity: String -> NorthWest | North | NorthEast | West | Center | East | SouthWest| South | SouthEast,\n                            logoWidth: Number,\n                            logoHeight: Number,\n                            logoWidthPercent: Number,\n                            logoHeightPercent: Number\n                        } \n                         */\n                        imageMagick(source)\n                            .overlayImage(watermark_params.logo, watermark_params.gravity, resizeTo(logoWidth, logoHeight))\n                            .write(destination, function (e) {\n                                callback(null, true);\n                            });\n                    } else if (type == \"crop_watermark\") {\n                        imageMagick(source)\n                            .resize(crop_params.width, crop_params.height, \"^\")\n                            .cropOnAspect(crop_params.gravity, crop_params.width, crop_params.height)\n                            .overlayImage(watermark_params.logo, watermark_params.gravity, resizeTo(logoWidth, logoHeight))\n                            .write(destination, function (e) {\n                                callback(null, true);\n                            });\n                    } else {\n                        callback(new Error(\"type is not valid\"), false);\n                    }\n                });\n            }\n\n            if (type == \"crop\") {\n                /*\n                 crop: {\n                     gravity: String -> NorthWest | North | NorthEast | West | Center | East | SouthWest| South | SouthEast,\n                     width: Number,\n                     height: Number\n                 } \n                 */\n                if (crop_params.width && crop_params.height) {\n                    imageMagick(source)\n                        .resize(crop_params.width, crop_params.height, \"^\")\n                        .cropOnAspect(crop_params.gravity, crop_params.width, crop_params.height)\n                        .write(destination, function (e) {\n                            console.log(e || 'Done. Path : ' + destination);\n                            callback(null, true);\n                        });\n                } else {\n                    callback(new Error(\"crop width x height is \"+crop_params.width+\" x \"+crop_params.height), false);\n                }\n            } else {\n                callback(new Error(\"type is not valid\"), false);\n            }\n        });\n    } else {\n        callback(\"source is \"+source+\", logo is \"+logo+\", destination is \"+destination+\", type is \"+type, false);\n    }\n};\n\nmodule.exports.apply = apply;\n"]}