Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

init

  • Loading branch information...
commit 9647ef9d8ff68b29356fbaa970ad6f5e9284bf3a 0 parents
Vadim authored
3  .gitignore
@@ -0,0 +1,3 @@
+.DS_Store
+node_modules
+*.sock
4 .npmignore
@@ -0,0 +1,4 @@
+support
+test
+examples
+*.sock
114 Readme.md
@@ -0,0 +1,114 @@
+
+# magician
+
+ Library for image manipulation. Requires imagemagick.
+
+# Here it is!
+
+ sMy://///////////////////////////////////:sMh`
+ .mN+//////////////////////////////////////mN-
+ +Mh/////////////////////////////////////sMs
+ `dN+////////////////////////////////////mN-
+ `````` +Mh///////////////////////////////////sMs
+ ```......``` .mN+//////////////////////////////////mN-
+ ``.-:+ooo/-..`` oMy:////////////////////////////////oMh
+ ``.-/y+::/oy:..` -Nm/////////////////////////////////dM/
+ ``.-oy-:/:-d/-.`` `hMo://////////////////////////////+Nm.
+ ``.-:sso+oyo-.`` +Mh//////////////////////////////:sMs
+ ``..-+yoso-.`` .mN//++ossyyyyyyyyyyyyyyyyyyyyyssodN/
+ `:/:-.````:dsyy``` `hMdyyso+//:::-----------::://++oyNm. `.-:/:`
+ :msosyyso+oNyhd.` oMy::::------........------:::::oNh` ``.-:/+osyysosm:
+ `oho////++oNhhNysso+//:--../Md/:::------.........-----::::/yMs..--://+ossyyysoo++////oho`
+ -oyysso++mdyNo/+++oosssyyyddhyyyyssssooooooooooossssyyyyhddyyysssoo++////////+ossyyo-
+ `.-:/osmdyNhoo++/////////////++++++++++ooo++++++++++/////////////++oossyysso/:-.`
+ `smymy/+oossyyyyyssooo+++++++/////////////+++++ooosssyyyydmso+/:-.``
+ +Nymy `.omdhyyhmmhssssyy+++yyyyyyy+:-/syooooyds//:--+dh`
+ :Nydd om+--:/-::-...::`:o/`:/..+..sy+`::....--ooh:..oN-
+ -Nyhm` `dd../ho/......+.`hNh`.+..+`.hdo`:/.....--oy-./dh`
+ .mhhN. +N+.-o-.......-/-.---/:--:/-.--::........::/yds:++o/
+ `--ddyN/` `+dy/...........-:::::osso:::/:--.........sNo.`s+--h:--:/++.
+ .y///+dNhy+` .yN:........-/ydddmmmmmmmmmmmmh+-.......hd` -y..+ms////yo.`
+ `:hyyyhhNy+dh:` -Ns......../NMMMMMMMMMMMMMMMMMm/....../N+ `ds+sooshsso+so`
+ so///yNymo///yh/.``sm:.......-/+ssydmNNNNNmhss++:....../my``-+hm:-.../yoooosss.
+ /hyyydNyddoosmyhhy/:hm/........./:odmmmmmmmd:/:......-omy:+yhyym:.....-ys//+oy-
+ so:::yMyhm-.ydsssshhmmdy/-.......-:////////:--....-:odhmdhyssssmo.....-yyso+ss
+ `/hhyyddhN:omysssssohd/ohhyo/:---------------::/oyhhs//myossssoym/....:hoo+++:
+ .h/::/dhNmmyssssssssdy-.:+oyhhddddhdddddddmmdyyo/:-.-hdssssssssyms/::+ys.
+ `-::hmyNdhhyssssssssms-....../NmdmdmNNdddmm:......-ydssssssssyhhs+o+/.
+ omymo`:ohhyssssssmy--....-mmdddmymmddNd.....-:hdssssssyhho-`
+ ``...----oNymh---:+sddysssshdys/..-dmhhhy+shhhmh.../sydhsssshdhs:-..````````
+ `-::::::::oNydd:::::::oNssssssymo..-hh+++++++++dy...smysssssyN+:::::::::::::::::--.`
+ `.::::::+Nhdm/::::::+Nyssssym/...-hh+++++++++dy....+msssssyN/:::::::::::::::::::-.
+ `-:::/osoo:::::::+Nsssssms....-dh+++++++++dy.....ydssssyN/::::::::::::::::-`
+ .-::::::::::::oNssssyN:....-dy+++++++++hh...../NsssssN+:::::::::::::-`
+ `.::::::::::ymsssohd-....-ms+++++++++hd.....-myosssNo::::::::::-.
+ .::::::::ddossodh-....:No+++++++++ym-....-dhossomy::::::::-`
+
+# Installation
+
+```npm install magician```
+
+# Dependencies
+
+The main dependency is ImageMagick. convert and identify command-line tools, in fact. If you are happy user of Mac, you can install ImageMagick using HomeBrew:
+
+```brew install imagemagick```
+
+# Features
+
+This is very early release, so Magician does not have a lot of features.
+
+* Resizing images
+* Getting dimensions of an image
+
+# Usage
+
+```
+magician = require 'magician'
+
+image = new magician __dirname + '/source.jpg', __dirname + '/target.jpg'
+
+image.resizeTo 100, 100, (err) ->
+ // done!
+
+```
+
+# Tests
+
+You can run tests using zap:
+
+```
+zap
+```
+
+# TODO List
+
+* Cropping
+* Resizing using ratio
+* Blurring image
+* getting base64 encoded content of image for data:URIs
+
+# License
+
+(The MIT License)
+
+Copyright (c) 2011 Vadim Demedes <sbioko@gmail.com>
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+'Software'), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2  index.js
@@ -0,0 +1,2 @@
+
+module.exports = require('./lib/magician');
26 lib/magician.coffee
@@ -0,0 +1,26 @@
+exec = require("child_process").exec
+
+class Magician
+
+ constructor: (@sourcePath, @destPath) ->
+
+ resizeTo: (width, height, callback) ->
+ if not width or width < 0 or not height or height < 0
+ return callback new Error "width and height should be bigger than 0"
+
+ exec "convert -resize #{ width }x#{ height } #{ @sourcePath } #{ @destPath }", (err, stdout, stderr) ->
+ callback no if callback
+
+ getDimensions: (callback) ->
+ that = @
+ exec "identify #{ @sourcePath }", (err, stdout, stderr) ->
+ dimensions = stdout.split(" ")[2].split "x"
+ that.width = dimensions[0]
+ that.height = dimensions[1]
+ callback {
+ width: that.width,
+ height: that.height
+ } if callback
+
+
+module.exports = Magician
36 lib/magician.js
@@ -0,0 +1,36 @@
+var Magician, exec;
+exec = require("child_process").exec;
+Magician = (function() {
+ function Magician(sourcePath, destPath) {
+ this.sourcePath = sourcePath;
+ this.destPath = destPath;
+ }
+ Magician.prototype.resizeTo = function(width, height, callback) {
+ if (!width || width < 0 || !height || height < 0) {
+ return callback(new Error("width and height should be bigger than 0"));
+ }
+ return exec("convert -resize " + width + "x" + height + " " + this.sourcePath + " " + this.destPath, function(err, stdout, stderr) {
+ if (callback) {
+ return callback(false);
+ }
+ });
+ };
+ Magician.prototype.getDimensions = function(callback) {
+ var that;
+ that = this;
+ return exec("identify " + this.sourcePath, function(err, stdout, stderr) {
+ var dimensions;
+ dimensions = stdout.split(" ")[2].split("x");
+ that.width = dimensions[0];
+ that.height = dimensions[1];
+ if (callback) {
+ return callback({
+ width: that.width,
+ height: that.height
+ });
+ }
+ });
+ };
+ return Magician;
+})();
+module.exports = Magician;
10 package.json
@@ -0,0 +1,10 @@
+{
+ "name": "magician"
+ , "version": "0.0.1"
+ , "description": "Library for image manipulation. Requires imagemagick."
+ , "keywords": ["image", "imagemagick", "magick", "resize"]
+ , "author": "Vadim Demedes <sbioko@gmail.com>"
+ , "dependencies": {}
+ , "main": "index"
+ , "engines": { "node": "0.4.x" }
+}
BIN  test/image.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 test/magician.test.coffee
@@ -0,0 +1,19 @@
+assert = require 'assert'
+
+module.exports=
+ setup: (test) ->
+ test.magician = require '../lib/magician'
+
+ 'test resizing image': (test) ->
+ image = new test.magician __dirname + '/image.jpg', __dirname + '/image_resized.jpg'
+ image.resizeTo 100, 100, (err) ->
+ resizedImage = new test.magician __dirname + '/image_resized.jpg'
+ resizedImage.getDimensions (dimensions) ->
+ assert.equal(dimensions.width, 100) && assert.equal(dimensions.height, 100)
+ test.done()
+
+ 'test getting dimensions of an image': (test) ->
+ image = new test.magician __dirname + '/image.jpg'
+ image.getDimensions (dimensions) ->
+ assert.equal(dimensions.width, 500) && assert.equal(dimensions.height, 250)
+ test.done()
Please sign in to comment.
Something went wrong with that request. Please try again.