Play Node-images Module---node. js Lightweight cross-platform image codec library

Source: Internet
Author: User
Tags readfile

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.