├── .npm ├── .gitignore ├── README └── npm-shrinkwrap.json ├── LICENSE ├── README.md ├── imagemagick.js ├── package.js └── smart.json /.npm/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /.npm/README: -------------------------------------------------------------------------------- 1 | This directory and the files immediately inside it are automatically generated 2 | when you change this package's NPM dependencies. Commit the files in this 3 | directory (npm-shrinkwrap.json, .gitignore, and this README) to source control 4 | so that others run the same versions of sub-dependencies. 5 | 6 | You should NOT check in the node_modules directory that Meteor automatically 7 | creates; if you are using git, the .gitignore file tells git to ignore it. 8 | -------------------------------------------------------------------------------- /.npm/npm-shrinkwrap.json: -------------------------------------------------------------------------------- 1 | { 2 | "dependencies": { 3 | "imagemagick": { 4 | "version": "0.1.3" 5 | } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Sylvain Gizard 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Meteor Imagemagick 2 | 3 | Meteor wrapped library [node-imagemagick](https://github.com/rsms/node-imagemagick) into a synchronous API, using Futures. 4 | 5 | ## Installation 6 | 7 | You need at least version 0.6.5 of Meteor. 8 | 9 | Meteor Imagemagick can be installed with [Meteorite](https://github.com/oortcloud/meteorite/). From inside a Meteorite-managed app: 10 | 11 | ``` sh 12 | $ mrt add imagemagick 13 | ``` 14 | 15 | ## API 16 | Based on node-imagemagick original doc. 17 | 18 | ### identify(path) 19 | 20 | Identify file at `path` and return an object `features`. 21 | 22 | Example: 23 | 24 | ```javascript 25 | var features = Imagemagick.identify('kittens.jpg'); 26 | console.log(features); 27 | ``` 28 | 29 | ### identify(args) 30 | 31 | Custom identification where `args` is an array of arguments. The result is returned as a raw string to `output`. 32 | 33 | Example: 34 | 35 | ```javascript 36 | var output = Imagemagick.identify(['-format', '%wx%h', 'kittens.jpg']); 37 | console.log('dimension: '+output); 38 | ``` 39 | 40 | ### readMetadata(path) 41 | 42 | Read metadata (i.e. exif) in `path` and return an object `metadata`. Modelled on top of `identify`. 43 | 44 | Example: 45 | 46 | ```javascript 47 | var metadata = Imagemagick.readMetadata('kittens.jpg'); 48 | console.log('Shot at '+metadata.exif.dateTimeOriginal); 49 | ``` 50 | 51 | ## convert(args) 52 | 53 | Raw interface to `convert` passing arguments in the array `args`. 54 | 55 | Example: 56 | 57 | ```javascript 58 | Imagemagick.convert(['kittens.jpg', '-resize', '25x120', 'kittens-small.jpg']); 59 | ``` 60 | 61 | ### resize(options) 62 | 63 | Convenience function for resizing an image, modelled on top of `convert`. 64 | 65 | The `options` argument have the following default values: 66 | 67 | ```javascript 68 | { 69 | srcPath: undefined, 70 | srcData: null, 71 | srcFormat: null, 72 | dstPath: undefined, 73 | quality: 0.8, 74 | format: 'jpg', 75 | progressive: false, 76 | width: 0, 77 | height: 0, 78 | strip: true, 79 | filter: 'Lagrange', 80 | sharpening: 0.2, 81 | customArgs: [] 82 | } 83 | ``` 84 | 85 | srcPath, dstPath and (at least one of) width and height are required. The rest is optional. 86 | 87 | Example: 88 | 89 | ```javascript 90 | Imagemagick.resize({ 91 | srcPath: 'kittens.jpg', 92 | dstPath: 'kittens-small.jpg', 93 | width: 256 94 | }); 95 | console.log('resized kittens.jpg to fit within 256x256px'); 96 | ``` 97 | 98 | ### crop(options) ### 99 | Convenience function for resizing and cropping an image. _crop_ uses the resize method, so _options_ and _callback_ are the same. _crop_ uses _options.srcPath_, so make sure you set it :) Using only _options.width_ or _options.height_ will create a square dimensioned image. Gravity can also be specified, it defaults to Center. Available gravity options are [NorthWest, North, NorthEast, West, Center, East, SouthWest, South, SouthEast] 100 | 101 | Example: 102 | 103 | ```javascript 104 | Imagemagick.crop({ 105 | srcPath: path, 106 | dstPath: 'cropped.jpg', 107 | width: 800, 108 | height: 600, 109 | quality: 1, 110 | gravity: "North" 111 | }); 112 | ``` 113 | -------------------------------------------------------------------------------- /imagemagick.js: -------------------------------------------------------------------------------- 1 | var Future = Npm.require("fibers/future"); 2 | var im = Npm.require("imagemagick"); 3 | 4 | Imagemagick = {}; 5 | 6 | ["identify", "readMetadata", "convert", "resize", "crop"].forEach(function(fn){ 7 | Imagemagick[fn] = function(args){ 8 | var future = new Future(); 9 | var cb = future.resolver(); 10 | 11 | im[fn](args, cb); 12 | 13 | return future.wait(); 14 | }; 15 | }); -------------------------------------------------------------------------------- /package.js: -------------------------------------------------------------------------------- 1 | Package.describe({ 2 | summary: "Imagemagick future-wrapped API" 3 | }); 4 | 5 | Npm.depends({ 6 | "imagemagick": "0.1.3" 7 | }); 8 | 9 | Package.on_use(function (api) { 10 | api.export('Imagemagick'); 11 | api.add_files("imagemagick.js", "server"); 12 | }); -------------------------------------------------------------------------------- /smart.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "imagemagick", 3 | "description": "Imagemagick wrapped for Meteor", 4 | "homepage": "https://github.com/sylvaingi/meteor-imagemagick", 5 | "author": "Sylvain Gizard ", 6 | "version": "0.1.2", 7 | "git": "https://github.com/sylvaingi/meteor-imagemagick.git" 8 | } 9 | --------------------------------------------------------------------------------