Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Up-for-discussion: change node-imagemagick dependency to GM + more #49

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
1a12ccb
Use custom imagemagick.
nathankot Sep 14, 2014
0614472
Use git url.
nathankot Sep 14, 2014
42d3ae2
Added the filenameId attribute.
SeyZ Mar 17, 2013
eacb68f
Merge branch 'wedis'
nathankot Nov 2, 2014
e6f6d36
Add gm dependency.
nathankot Nov 2, 2014
8736cfe
Tabs to spaces.
nathankot Nov 2, 2014
6607e9d
Setup testing.
nathankot Nov 2, 2014
2d27ca9
Formatting.
nathankot Nov 2, 2014
8835f49
Watch script.
nathankot Nov 2, 2014
9050409
Bootstrap - make it work with watch.
nathankot Nov 2, 2014
4255f88
Expose providersRegistry.
nathankot Nov 2, 2014
35ca518
Ensure that the provider actually writes the new file.
nathankot Nov 2, 2014
99c53ed
Thumbnail should be smaller.
nathankot Nov 2, 2014
a379528
Add test for resampling.
nathankot Nov 2, 2014
997a508
Reorganise specs.
nathankot Nov 2, 2014
f6a5ae4
README first - tweak how attachment configuration looks.
nathankot Nov 3, 2014
08c1772
Tweak the spec.
nathankot Nov 3, 2014
7c9c252
Code clean up.
nathankot Nov 3, 2014
5b18829
If spacing.
nathankot Nov 3, 2014
4b33166
Main functionality is now working using gm.
nathankot Nov 3, 2014
cae2508
Restructure and cleanup.
nathankot Nov 3, 2014
fa5b4bf
testFindImageMagickFormats belongs simply in test_formats.js
nathankot Nov 3, 2014
5734f76
Revert "testFindImageMagickFormats belongs simply in test_formats.js"
nathankot Nov 3, 2014
44e47fd
Remove logic that derives logic from imagemagick - seems overkill
nathankot Nov 3, 2014
7b13f13
Support for non-image files.
nathankot Nov 3, 2014
b3d25ff
Remove imagemagick dependency.
nathankot Nov 3, 2014
6137822
Remove some stuff.
nathankot Nov 3, 2014
e5abb58
Need to prefix storage style path with slash.
nathankot Nov 3, 2014
939cf94
Subclass gm, dont mix image objects.
nathankot Nov 3, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ logs
results

node_modules
test/tmp/*
test/fixtures/*-thumbnail*
test/fixtures/*-original*
116 changes: 35 additions & 81 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,23 @@ PostSchema.plugin(attachments, {
// keep the original file
},
small: {
resize: '150x150'
transform: function(image) {
return image
.resize(150, 150)
;
}
},
medium: {
resize: '120x120'
transform: function(image) {
return image
.resize(120, 120)
;
}
},
medium_jpg: {
'$format': 'jpg' // this one changes the format of the image to jpg
options: {
format: 'jpg' // this one changes the format of the image to jpg
}
}
}
}
Expand Down Expand Up @@ -124,14 +134,24 @@ MySchema.plugin(attachments, {
// keep the original file
},
thumb: {
thumbnail: '100x100^',
gravity: 'center',
extent: '100x100',
'$format': 'jpg'
options: {
format: 'jpg'
},
transform: function(image) {
return image
.thumbnail(100, 100)
.gravity('center')
.extend(100, 100)
}
},
detail: {
resize: '400x400>',
'$format': 'jpg'
options: {
format: 'jpg'
},
transform: function(image) {
return image
.resize(400, 400, '>')
}
}
}
}
Expand Down Expand Up @@ -171,25 +191,9 @@ Example:
}
```

### Styles and ImageMagick Transformations
### Styles and Transformations

Transformations are achieved by invoking the **convert** command from ImageMagick and passing all the properties of the style as arguments.

For more information about convert, take a look at http://www.imagemagick.org/script/command-line-options.php

Example in convert command:

convert source.png -resize '50%' output.png

Example in plugin options:

```javascript
styles: {
small: {
resize: '50%'
}
}
```
Transformations are achieved using the [gm library](https://github.com/aheckmann/gm).

#### Keeping the Original File

Expand All @@ -201,30 +205,19 @@ styles: {
}
```

#### Multiples Transformations

Use another properties under the style to provide more transformations

```javascript
styles: {
small: {
crop: '120x120',
blur: '5x10' //radius x stigma
}
}
```

More information about 'blur' at the [ImageMagick website] http://www.imagemagick.org/script/command-line-options.php#blur

#### Changing the Destination Format

You can change the destination format by using the special transformation '$format' with a known file extension like *png*, *jpg*, *gif*, etc.
You can specify a format option to change the format of the output.

Example:

styles: {
as_jpeg: {
'$format': 'jpg'
options: {
format: 'jpg'
}
}
}

Expand Down Expand Up @@ -252,45 +245,6 @@ To add a format call the following method before using the plugin in the mongoos
attachments.registerDecodingFormat('BMP');
```

##### Formats Provided by ImageMagick

ImageMagick (or GraphicsMagick) list the supported formats when calling `convert -list format` (or `identify`).
The formats are flagged to show which operations are supported with each:

* `*` native blob support (only ImageMagick, not GraphicsMagick)
* `r` read support
* `w` write support
* `+` support for multiple images

You can register the formats that are supported for read operation like so:

```javascript
attachments.registerImageMagickDecodingFormats();
```

To register formats supporting different operations there is a more general function. Specifying certain operations will select only those formats that support all of them. Formats supporting only a subset won't be included. The following call yields the list of formats that support `read`,`write`,`multi`:

```javascript
attachments.registerImageMagickFormats({ read: true, write: true, multi: true });
```

If you want to use the output list that was generated for your own benefit you can specify a callback as second argument to that above method. Note, however, that in that case the supported decoding formats won't be changed on the plugin.

You could use that callback to assure that the formats you want your client to support are indeed supported by the backing ImageMagick (or GraphicsMagick) installation. For example, checking TIFF support:

```javascript
attachments.registerImageMagickFormats({ read: true }, function(error, formats) {
if (error) throw new Error(error);
else if (formats && formats.length > 0) {
if (formats.indexOf('TIFF') < 0) {
throw new Error('No TIFF support!');
}
} else {
throw new Error("No formats supported for decoding!");
}
});
```

### Contributors

* [Johan Hernandez](https://github.com/thepumpkin1979)
Expand Down
Loading