سؤال

ImageMagick and RMagick both have a setting/attribute for "density", which is what they call resolution. I can pass it a value of 200 and it should set the resolution to 200x200 when the image is written to either a file or to_blob.

In the Rails console I can load the image, then set the density, and if I check it, it will tell me the density (originally 300x300) is now 200x200, but when I write it out to a file, the resolution is 300x300.

The only way I've successfully been able to change the resolution is by creating a new image of the same width and height, then overlay the original image. This, however, distorts the output, no matter what settings I use (I tried setting the original to fully opaque, the "new" to fully transparent, and even used the CopyCompositeOperation, which should fully replace the "new" image).

I have tried setting density like this:

image.density = "200"

And like this

image.write("test.jpg") {self.density="200"}

And both.

Nothing works... any ideas?

To be clear... I don't want to resize the image, I want to change the print resolution. I want the dimensions to remain the same (i.e. width/height should NOT change).

هل كانت مفيدة؟

المحلول

This was an issue with the version of ImageMagick that AWS has in its repositories. Removing that version and installing from source made the density setting work. Also, if you want the resolution change to be reflected in Windows applications, you need to strip the "8bim" profile from the image:

image.profile!("8bim",nil)
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top