Closed wloske closed 8 years ago
I don't think either customIn or customOut work for multi-parameter options. (They do work for things like -strip
.) But if you modify the existing code slightly, you can pass in an array of options and values and then it works swimmingly. I needed to move the customOut emit just below the sharpen code such that customOut args are executed after the resize rather than before. Then you can cause -draws to be emitted, &c.
options.customOut: ["-emboss", "1"]
if (isValidArray(sizeOptions.customOut)) {
sizeOptions.customOut.forEach(function(val){ image.out(val); });
}
The way I read the code, there never was a way this could have worked. The routines of customOut should be expanded to offer all of the output option the underlying gm package offers.
The newy introduced sharpen command does exactly that. I replicated that behaviour in responsive_images.js to work for emboss, too. Like so:
In module responsive_images I added:
if (sizeOptions.emboss) {
image
.emboss(sizeOptions.emboss);
}
and my config changed to:
options : {
sizes : [{
rename : false,
aspectRatio : true,
width : 390,
sharpen : {
sigma : 0.5,
radius : 2
},
emboss : 1
}]
}
which yields in the command gm "convert" "-quality" "100" "test_input/test.png" "-resize" "390x" "-sharpen" "2x0.5" "-emboss" "1" "test_output/test.png"
which is exactly what I wanted. Emboss is not the command I needed, actually it was sharpen, which is available now.
I'd appreciate if Andi would comment on this. There might be more in gm which could be of use but I don't know how compatible to im this all would be.
Hi all,
The original code for customOut was from a pull request https://github.com/andismith/grunt-responsive-images/pull/75 by @paazmaya .
It didn't come with any documentation. Maybe I shouldn't have merged it in the first place.
Hopefully he can shed some light.
Thanks, Andi
O ou...
Well the PR was adding links to the revelant section of the package used, namely gm
https://github.com/aheckmann/gm#custom-arguments
But the examples are surely missing.
I must confess I haven't used this plugin since and I am guessing that the other participants of this issue have already better understanding of the usage than I do....
@wloske did you try customOut : '-emboss 1'
?
What part of customOut are you trying to use @wloske?
Hi all ... I wanted to use "sharpen" as stated above. This is now implemented. The customOut Feature should be fixed or taken out. And @paazmaya : no, I did not try what you suggest.
customOut: '-emboss 1'
=> "-emboss 1"
, which doesn't work. We want "-emboss" "1"
.
The only way to do this reasonably is to pass an array. An object doesn't work because for some of the gm convert
options take > 1 arg and you have have duplicate options. For example -set
. Here's what I'm doing with my locally modified copy in order to add copyright info to all of the generated images.
Works like a charm.
customIn: ['-interlace', 'line'], // emit progressive jpegs.
customOut: ['-set', 'comment', 'Copyright Yormom, all rights reserved',
'+profile', '*', // remove all exif and color profiles.
'-gravity', 'SouthEast',
'-font', 'Arial', '-pointsize', '12',
'-fill', '#445', '-draw', 'text 10,10 \'\u00A9 Yormom\'',
'-fill', '#ffe', '-draw', 'text 11,11 \'\u00A9 Yormom\''],
Here's a patch to get you started if you want this level of fun.
--- node_modules/grunt-responsive-images/tasks/responsive_images.bak 2015-10-05 18:03:11.564669200 -0700
+++ node_modules/grunt-responsive-images/tasks/responsive_images.js 2015-10-07 22:20:03.068334100 -0700
@@ -361,11 +361,8 @@
}
}
- if (sizeOptions.customIn) {
- image.in(sizeOptions.customIn);
- }
- if (sizeOptions.customOut) {
- image.out(sizeOptions.customOut);
+ if (isValidArray(sizeOptions.customIn)) {
+ sizeOptions.customIn.forEach(function(val){ image.in(val); });
}
if (sizeOptions.filter) {
@@ -392,6 +389,10 @@
image
.sharpen(sizeOptions.sharpen.radius, sizeOptions.sharpen.sigma);
}
+
+ if (isValidArray(sizeOptions.customOut)) {
+ sizeOptions.customOut.forEach(function(val){ image.out(val); });
+ }
image.write(dstPath, function (error) {
if (error) {
@johnv-git PR?
Added as pull#98
Merged in to 0.1.9
I tried to use the customOut feature but failed. Might be I did not understand how it should work. An example in the docs would be nice.
What I tried:
The picture is being scaled but filter is not applied. Sharpening is. When I watch the command being executed via console I get an error saying
Warning: Command failed: gm convert: Unable to open file (1) [No such file or directory].
and aconsole.log()
but I do get a scaled image.Logging in
node_modules/gm/lib/command.js#190
reveals the following command line being executedgm "convert" "-quality" "100" "test_input/test.png" "emboss:1" "-resize" "390x" "-sharpen" "2x0.5" "test_output/test.png"