imaginator
v1.1.2
Published
Converts image tags to use data URIs instead of image files an HTML document.
Readme
Imaginator
An Express middleware that converts image tags to use data URIs instead of image files an HTML document.
Installation
> npm install --save imaginatorUsage
const express = require('express');
const path = require('path');
const imaginator = require('imaginator');
const app = express();
app.use(imaginator(path.join(__dirname, 'public'), 'img.datauri'));
app.use(express.static(path.join(__dirname, 'public')));
app.listen(3000);imaginator(publicDirectory, selector = 'img')
publicDirectory: The path to the directory where the hosted public files (including the images) are stored. In most cases, it should be set topath.join(__dirname, 'public').selector: The CSS-style selector for the tags to be affected. Its default value is'img'i. e. Allimgtags will be affected.
Example
index.html before applying Imaginator:
<!DOCTYPE html>
<html>
<head>
<title>Hi</title>
</head>
<body>
Hello world! <br/>
<img src='images/image1.png'>
<img src='images/image2.png'>
<img class='datauri' src='images/image3.png'>
</body>
</html>index.html after applying Imaginator:
<!DOCTYPE html>
<html>
<head>
<title>Hi</title>
</head>
<body>
Hello world! <br/>
<img src='images/image1.png'>
<img src='images/image2.png'>
<img class='datauri' src='data:image/png;base64,...=='>
</body>
</html>Made with ❤ by Param.
