Node.js 圖像處理包:gm
gm 是 Node.js 的 GraphicsMagick 和 ImageMagick。
常規使用:
var fs = require('fs') , gm = require('./gm'); // resize and remove EXIF profile data gm('/path/to/my/img.jpg') .resize(240, 240) .noProfile() .write('/path/to/resize.png', function (err) { if (!err) console.log('done'); }); // obtain the size of an image gm('/path/to/my/img.jpg') .size(function (err, size) { if (!err) console.log(size.width > size.height ? 'wider' : 'taller than you'); }); // output all available image properties gm('/path/to/img.png') .identify(function (err, data) { if (!err) console.log(data) }); // pull out the first frame of an animated gif and save as png gm('/path/to/animated.gif[0]') .write('/path/to/firstframe.png', function (err) { if (err) console.log('aaw, shucks'); }); // auto-orient an image gm('/path/to/img.jpg') .autoOrient() .write('/path/to/oriented.jpg', function (err) { if (err) ... }) // crazytown gm('/path/to/my/img.jpg') .flip() .magnify() .rotate('green', 45) .blur(7, 3) .crop(300, 300, 150, 130) .edge(3) .write('/path/to/crazy.jpg', function (err) { if (!err) console.log('crazytown has arrived'); }) // annotate an image gm('/path/to/my/img.jpg') .stroke("#ffffff") .drawCircle(10, 10, 20, 10) .font("Helvetica.ttf", 12) .drawText(30, 20, "GMagick!") .write("/path/to/drawing.png", function (err) { if (!err) console.log('done'); }); // creating an image gm(200, 400, "#ddff99f3") .drawText(10, 50, "from scratch") .write("/path/to/brandNewImg.jpg", function (err) { // ... });
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!