excellenteasy / grunt-image-resize

Unmaintained. If you'd like to take this over please let us know. Resizing images made easy - thanks to imagemagick.
MIT License
57 stars 46 forks source link

Feature Request: Filter Option for Resizing. #17

Open mpelham opened 10 years ago

mpelham commented 10 years ago

Hey there! Great bit of work you've got here!

I'm currently using your plugin to downscale some PNGs for retina / non-retina support. Our artist took a great deal of care and time ensuring there was no aliasing of our PNGs for optimal compression, however, when downscaling, we run into a minor issue where Aliasing is applied.

Original: png charset utf-8-1

Downscaled: png charset utf-8

As there is no Filter Option as part of the grunt-image-resize task, there is no easy way to pass this into GraphicsMagick, however, it seems to be a fairly trivial task to add it.

On line 89 of image_resize.js:

var resizer = gm(filepath)
 .resize(imOptions.width, imOptions.height);

If I hack in:

var resizer = gm(filepath)
 .filter('Point')
 .resize(imOptions.width, imOptions.height);

I receive a Downscaled image with my specific use case solved for! Hooray!

png charset utf-8

Obviously, this is not the final solution for the code, I would propose we allow a new Option to be passed via Grunt, which is "filter" (Or "interpolation", I don't really care what we name it). Filter would default to what GraphicsMagick defaults to if not passed via Grunt.

Available options would include: Point | Box | Triangle | Hermite | Hanning | Hamming | Blackman | Gaussian | Quadratic | Cubic | Catrom | Mitchell | Lanczos | Bessel | Sinc

From GraphicsMagick documentation, here: http://www.graphicsmagick.org/GraphicsMagick.html#details-filter

As most people want clean, smooth, aliased resizes which Grunt Image Resizes supports, this is definitely a unique use case, but it would be great to see it added!

normanrz commented 10 years ago

Hi @mpelham, seems like you put quite some effort in this feature request already. Could you make a pull request out of it?

denisnarushevich commented 10 years ago

+1 I'm looking for a way to upscale 8bit graphics for my game, without AA.

denisnarushevich commented 10 years ago

Actually gm also has scale() method, which is same as filter("point").resize(), but faster.

mpelham commented 9 years ago

Hi @normanrz!

Sorry to be off the loop, this was actually a quick hackjob with some poor documentation (on my end) that worked perfectly for my use-case.

I'm glad that @dnarushevich jumped in to provide an alternate use case, and the GM method. In my use-case, I run this rarely to optimize external_assets before dropping them onto S3 with a week cache at least, so "faster" isn't required.

I can't promise I'll get patches done anytime soon (I keep lazily dropping in the two lines I need when updates come out, sorry), but @dnarushevich / @normanrz, would you prefer something that allows unique resizer logic, and/or a series of options?

I would imagine you can pass either a function in the grunt command for the actual resize function, to satisfy Denis's use case, or options to filter resize.