Johann
Johann

Reputation: 21

How to resize to fit without antialiasing with rmagick

What I'm not looking for

I'm currently not searching how to resize to fit without antialiasing with ImageMagick. I know this answer can be found quickly on the web as quite every questions have been already asked on ImageMagick.

Context

The context is I get a big image that I have to resize to fit multiple kind of screens. In almost all cases, everything goes fine, but for little dimensions, I've got some blur issues due to aliasing. My images are all black & white and very simple (it's barcodes), so I don't need any aliasing.

What I'm looking for

What I'm looking for is how to resize properly with RMagick, the ruby implementation of ImageMagick. For the moment, I'm using the resize_to_fit method to resize an image but I've got an issue with aliasing and there is no options to pass to the method which could disable it.

I'm currently considering writing a method that does the same as resize_to_fit but with the ability to disable aliasing but no decision taken for the moment.

Upvotes: 2

Views: 436

Answers (1)

An RMagick User
An RMagick User

Reputation: 354

You'll get better results using a special-purpose resampling filter for the smaller sizes. Different filters have different strengths and weaknesses depending on the kind of image you're resizing. Try using the resize method instead of resize_to_fit. The resize method lets you specify which filter to use. Here's information about ImageMagick's filters. You may have to do some trial-and-error evaluation to see which filter works best with your images.

Also remember that JPEG images naturally introduce compression artifacts, so you might try saving these images as GIFs or PNGs or even TIFFs, if you're not already doing so.

Need some help with computing the new size of the image? You can couple resize with change_geometry to get the behavior of resize_to_fit.

Upvotes: 3

Related Questions