Skip to navigation
Nodejs express image server and qr image server
07.01.18
var path = require('path'); var gm = require( 'gm' ); var express = require('express'); var fs = require('fs'); var qr = require('qrcode') var app = express(); var mime = { html: 'text/html', txt: 'text/plain', css: 'text/css', gif: 'image/gif', jpg: 'image/jpeg', png: 'image/png', svg: 'image/svg+xml', js: 'application/javascript' }; app.get("/qr/*", function (req, res) { qr.toDataURL('hello', function (err, url) { var data = url.replace(/^data:image\/\w+;base64,/, ''); var img = new Buffer(data,'base64'); res.writeHead(200, { 'Content-Type': 'image/png', 'Content-Length': img.length }); res.end(img); }); }); app.get("/", function (req, res) { var gm = require( 'gm'); gm(200, 200, '#000F') .setFormat('png') .fill('black') .drawCircle( 50, 50, 60, 80 ) .toBuffer(function( error, buffer ) { if(error) { console.log( error ); } res.setHeader('Content-Type', 'image/png'); res.setHeader('Content-Length', Buffer.byteLength(buffer)); res.writeHead(200); res.end(buffer); } ); }); app.listen(3000, function () { console.log('Listening on http://localhost:3000/'); });
https://github.com/soldair/node-qrcode
Reply
Anonymous
sudo apt-get install imagemagick
07.01.18
Reply
Anonymous
Information Epoch 1732679512
Store numerical data in flat files.
Home
Notebook
Contact us