{"_id":"@baitic/docxtemplater-image-module","_rev":"2-ad8715961fb3607ce9c227430444a196","name":"@baitic/docxtemplater-image-module","dist-tags":{"latest":"3.1.0"},"versions":{"3.1.0":{"name":"@baitic/docxtemplater-image-module","version":"3.1.0","description":"Image Module for docxtemplater","main":"es6/index.js","scripts":{"test:coverage":"istanbul cover _mocha --  es6/test.js","compile":"rimraf js && mkdirp js && babel es6 --out-dir js","preversion":"npm test && npm run browserify && npm run uglify","test:compiled":"mocha js/test.js","test:es6":"mocha es6/test.js","lint":"eslint .","test":"npm run compile && npm run test:compiled","browserify":"mkdir build -p && browserify --insert-global-vars __filename,__dirname -r ./js/index.js -s ImageModule > build/imagemodule.js","uglify":"uglifyjs build/imagemodule.js > build/imagemodule.min.js"},"devDependencies":{"babel-cli":"^6.11.4","babel-eslint":"^7.1.1","babel-preset-es2015":"^6.3.13","browserify":"^14.0.0","chai":"^3.4.1","eslint":"^3.15.0","image-size":"^0.5.1","istanbul":"^0.4.5","jszip":"^2.6.1","mkdirp":"^0.5.1","mocha":"^3.2.0","rimraf":"^2.5.4","uglifyjs":"^2.4.10"},"repository":{"type":"git","url":"git+https://github.com/open-xml-templating/docxtemplater-image-module.git"},"author":{"name":"Edgar Hipp"},"license":"MIT","dependencies":{"xmldom":"^0.1.27"},"peerDependencies":{"@baitic/docxtemplater":"^3.25.2"},"bugs":{"url":"https://github.com/open-xml-templating/docxtemplater-image-module/issues"},"homepage":"https://github.com/open-xml-templating/docxtemplater-image-module#readme","directories":{"example":"examples"},"gitHead":"f769825f8f9bd269f1a05dd7db7b1258a83664d8","_id":"@baitic/docxtemplater-image-module@3.1.0","_nodeVersion":"15.8.0","_npmVersion":"6.13.1","dist":{"integrity":"sha512-6EeOGaE62ctQYbDzswyYKYxBSqrG01QO58rEUhu8N9U+m9/Opacdw9yhPFJxmE4xQlHPTMTIhDzxvZHgo38liQ==","shasum":"6a72810f6d41834e0e5967170c3a5badd5893b8b","tarball":"https://registry.npmjs.org/@baitic/docxtemplater-image-module/-/docxtemplater-image-module-3.1.0.tgz","fileCount":14,"unpackedSize":65578,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJh12PxCRA9TVsSAnZWagAAFwoP/AxxJd9GDoR1DJPc+qoQ\nWQ5hk7z54JhEKGAV5whCCkGPreSOOmrxfAh/9MuKIe9rh5sHg5wrKYE/j9qR\nfNJdZZLvOe4h4hRAdirtv2WZxDxJY8qSDRtO21/ZqXBOj4djRa8Bv8GC5lU1\nsPt35HjUlzYAtcnNDXVwLr9G4sjUmIF48OukyrlVDVfNX7PL1JtTPPrHz9Kg\nE55+7OM7j/PjH9vHWs3k1p2CC8dS0/jgwGn2zf7VEJQl+7l4HDzEV3oeF4Tb\njhI52dVHBrKPtz0X4Ut115475/hhXbw7QrIIEn1gTCpz2yTNuUNv7hyHQTA5\nZcEbsG2mHFYH14jH0nbShszbVNNeExxhd0NyQvokPL49NywUTCSNl7m7GZpq\npK7/ZtMrQmSB26mXJQRCCBXfFg10ihN0M3GWLzOBpxeeY7bOL21Xcv0IL8xB\nAzvvbUFyQUMravu+N+ZvuZsa2uCyiGDgrP6t/NJ6spd9N8CqbikzpO9MlLKt\n9AqWr7whlBdY+Omf/uBGZAqGuVn9+3WisUeUapRNa2TF1/UtY4YUknEGJfKL\npxQOufZQoLIpLyeoFjnxtuhKzsFfL7zYe+D4hNTr9iIDefbuMRsI6U3hBlWu\nbH3A08Bt1lCI/UH2haWhFxVZPyAPdeSwqRoQe7pHlmmjE6o/R4oHVboEL3H+\nUcO2\r\n=3uXM\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDLZucG3MoH56R1VysEtLH1xoNsyb5l0chk9YUEG7fdngIgAnaR7FcFjHZzrXxxBxa2xNoM94tfbTDT1llpoPoQMyM="}]},"_npmUser":{"name":"jhereu","email":"jhereumayo@gmail.com"},"maintainers":[{"name":"segarcialo","email":"sgarcia@baitic.com"},{"name":"jhereu","email":"jhereumayo@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/docxtemplater-image-module_3.1.0_1632236991423_0.4817011596959422"},"_hasShrinkwrap":false}},"time":{"created":"2021-09-21T15:09:51.380Z","3.1.0":"2021-09-21T15:09:51.561Z","modified":"2022-04-04T17:31:49.739Z"},"maintainers":[{"name":"segarcialo","email":"sgarcia@baitic.com"},{"name":"jhereu","email":"jhereumayo@gmail.com"}],"description":"Image Module for docxtemplater","homepage":"https://github.com/open-xml-templating/docxtemplater-image-module#readme","repository":{"type":"git","url":"git+https://github.com/open-xml-templating/docxtemplater-image-module.git"},"author":{"name":"Edgar Hipp"},"bugs":{"url":"https://github.com/open-xml-templating/docxtemplater-image-module/issues"},"license":"MIT","readme":"This version is only compatible with @baitic/docxtemplater version 3\n\nHere is a compatibility table :\n\n| image-module  | docxtemplater |\n| ------------- | :-----------: |\n| version 3     |   version 3   |\n| version 1.0.4 | version 2.1.5 |\n| version 1.0.0 | version 2.0.0 |\n\n[![Build Status](https://travis-ci.org/open-xml-templating/docxtemplater-image-module.svg?branch=master&style=flat)](https://travis-ci.org/open-xml-templating/docxtemplater-image-module) [![Download count](http://img.shields.io/npm/dm/docxtemplater-image-module.svg?style=flat)](https://www.npmjs.org/package/docxtemplater-image-module) [![Current tag](http://img.shields.io/npm/v/docxtemplater-image-module.svg?style=flat)](https://www.npmjs.org/package/docxtemplater-image-module) [![Issues closed](http://issuestats.com/github/open-xml-templating/docxtemplater-image-module/badge/issue?style=flat)](http://issuestats.com/github/open-xml-templating/docxtemplater-image-module)\n\n# Installation:\n\nYou will need docxtemplater `npm install @baitic/docxtemplater`\n\nThen install this module: `npm install @baitic/docxtemplater-image-module`\n\n# Usage\n\nYour docx should contain the text: `{%image}`\n\n```\nvar ImageModule=require('@baitic/docxtemplater-image-module')\n\nvar opts = {}\nopts.centered = false;\nopts.getImage=function(tagValue, tagName) {\n    return fs.readFileSync(tagValue);\n}\n\nopts.getSize=function(img,tagValue, tagName) {\n    return [150,150];\n}\n\nvar imageModule=new ImageModule(opts);\n\nvar zip = new JSZip(content);\nvar docx=new Docxtemplater()\n    .attachModule(imageModule)\n    .loadZip(zip)\n    .setData({image:'examples/image.png'})\n    .render();\n\nvar buffer= docx\n        .getZip()\n        .generate({type:\"nodebuffer\"});\n\nfs.writeFile(\"test.docx\",buffer);\n```\n\nTo understand what `img`, `tagValue`, `tagName` mean, lets take an example :\n\nIf your template is :\n\n```\n{%myImage}\n\nand your data:\n\n{\n    \"myImage\":'sampleImage.png'\n}\n\ntagValue will be equal to \"sampleImage.png\", tagName will be equal to \"myImage\" and img will be what ever the getImage function returned\n```\n\nOne of the most useful cases of this is to set the images to be the size of that image.\n\nFor this, you will need to install the [npm package 'image-size'](https://www.npmjs.com/package/image-size) then, write:\n\n```\nopts = {centered:false}\nopts.getImage=function(tagValue) {\n    return fs.readFileSync(tagValue,'binary');\n}\nopts.getSize=function(img) {\n   sizeOf=require('image-size');\n   sizeObj=sizeOf(img);\n   console.log(sizeObj);\n   return [sizeObj.width,sizeObj.height];\n}\nimageModule=new ImageModule(opts);\n```\n\n# Centering images\n\nYou can center the images using opts.centered=true or by using {%%image} instead of {%image} in your documents\n\n# Size and path based on placeholder\n\nYou can have customizable image loader using the template's placeholder name.\n\n```\nopts.getImage = function (tagValue, tagName) {\n    if(tagName === 'logo')\n        return fs.readFileSync(__dirname + '/logos/' + tagValue);\n\n    return fs.readFileSync(__dirname + '/images/' + tagValue);\n};\n```\n\nThe same thing can be used to customize image size.\n\n```\nopts.getSize = function (img, tagValue, tagName) {\n    if(tagName === 'logo')\n        return [100, 100];\n\n    return [300, 300];\n};\n```\n\n# Notice\n\nFor the imagereplacer to work, the image tag: `{%image}` needs to be in its own `<w:p>`, so that means that you have to put a new line after and before the tag.\n\n# Testing\n\nYou can test that everything works fine using the command `mocha`. This will also create some docx files under the root directory that you can open to check if the generation was correct.\n\n# Building in the browser\n\nYou can build a release for the browser with the following commands\n\n```\nnpm install\nnpm run preversion\nnpm run compile\n```\n\nYou will have build/imagemodule.js.\n","readmeFilename":"README.md"}