node. JS Lightweight cross-platform image codec library
Github:https://github.com/zhangyuanwei/node-images
Features Functional characteristics
- Lightweight: No need to install any image processing libraries.
- Cross-platform: a compiled. node file is released under Windows and can be downloaded.
- Easy to use: jquery-style API, simple to rely on.
What can we do with this plugin, the common watermark can be added, simple amplification and compression processing.
Instance:
//encode picture dependent module https://github.com/zhangyuanwei/node-imagesvarImages = require ("Images");varFS = require ("FS");varPath = require ("Path"); function ReadFile (SRC,DST) {//To determine if the file takes time, you must synchronize if(Fs.existssync (src)) {//Read FolderFs.readdir (src,function (err,files) {if(err) {Throwerr; } Files.foreach (function (FilePath) {console.log (DST); //url+ "/" +filename not available/direct connection, UNIX system is "/", Windows system is "\" varURL =Path.join (Src,filepath), dest=Path.join (Dst,filepath); Fs.stat (Url,function (err,stats) {if(ERR)Throwerr; //is a file if(Stats.isfile ()) {//The regular verdict is the picture if(/.*\. (jpg|png|gif) $/i.test (URL)) {encoderimage (url,dest); } }Else if(Stats.isdirectory ()) {exists (url,dest,readfile); } }) }); }); }Else{ Throw "No files,no such!" }}//the processing file here is a bit related to replication, the output to detect whether the file exists, there is no new filefunction exists (url,dest,callback) {fs.exists (dest,function (exists) {if(exists) {callback&&callback (Url,dest); }Else{ //second parameter directory permissions, default 0777 (read and Write permissions)Fs.mkdir (dest,0777, function (err) {if(ERR)Throwerr; Callback&&callback (Url,dest); }); } }); }function Encoderimage (sourceimg,destimg) {images (sourceimg)//Loading image files. Size ( +)//equal to 1000 pixels wider than the scaled image. Draw (Images ("pficon.jpg"),Ten,Ten)//draw a logo at (10,10). Save (destimg,{quality: - //save picture to file, image quality is });} ReadFile ("./SRC",". /Out"); Module.exports=ReadFile;
Play Node-images Module---node. js Lightweight cross-platform image codec library