Rmagick convert image quality

728 views
Skip to first unread message

Ibrahim Awwal

unread,
May 10, 2012, 11:18:25 PM5/10/12
to carri...@googlegroups.com
Hi,

I'm using carrierwave to do some processing with PDFs. I upload a PDF in my application and then use Rmagick to convert it to an image (PNG specifically), and later I use these images and crop regions out of them and create new files. Everything works, but the image quality is pretty bad. The images contain text (both typeset and handwritten) and sometimes the text becomes illegible. I've tried a lot of things to set the image quality when converting from PDF to PNG but it seems like no matter what I do the compression is really bad. How can I set the compression quality when using process :convert? https://github.com/jnicklas/carrierwave/wiki/How-to%3A-Specify-the-image-quality did not work for me at all.

I'm completely fine with patching random parts of carrierwave or Rmagick for now if necessary, as this is kind of a time critical project and we're going to take a step back and refactor everything after we're done with the part we're doing right now.

(Also fine with using Minimagick instead if it makes a difference).

Thanks!

-Ibrahim

Ibrahim Awwal

unread,
May 11, 2012, 12:15:32 AM5/11/12
to carri...@googlegroups.com
Hmm, I found a possible (hacky) solution to my problem. It seems like the default DPI when reading PDF files is 72dpi, and by setting this to 150dpi the quality is a bit better. It still degrades when saving/converting but for now this is a reasonable hack. I had to change Rmagick.rb in my local version of carrierwave and add the density parameter to ::Magick::Image.read in manipulate!. Perhaps this can be exposed somehow in a clean way but I'm not really a Ruby expert so I don't know the best way to do that.

-Ibrahim

Jacob Tjørnholm

unread,
May 11, 2012, 2:05:21 AM5/11/12
to carri...@googlegroups.com
I recently made a small patch to support setting write options in #manipulate!. See the example here: https://github.com/jnicklas/carrierwave/pull/726

Perhaps something similar would be useful for read options? Something like this: https://gist.github.com/2657836

/Jacob


--
You received this message because you are subscribed to the Google Groups "carrierwave" group.
To view this discussion on the web visit https://groups.google.com/d/msg/carrierwave/-/gcED5ocnMmwJ.

To post to this group, send email to carri...@googlegroups.com.
To unsubscribe from this group, send email to carrierwave...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/carrierwave?hl=en.

Ibrahim Awwal

unread,
May 11, 2012, 2:46:15 AM5/11/12
to carri...@googlegroups.com
Yeah, I actually just found that, that might help with the issue I was
having trying to set the quality upon conversion, but it's definitely
the case that reading my 200dpi source at 72dpi is causing a lot of
information to be lost even before the conversion. I agree, something
similar for read options would be nice.
--Ibrahim Awwal

Jacob Tjørnholm

unread,
May 30, 2012, 3:41:24 AM5/30/12
to carri...@googlegroups.com
I looked briefly over this again, but I'm not changing it right now, for two reasons: 

1) It wouldn't be symmetrical with the write options feature, because it would not be possible to set the read options from within the block given to manipulate! (because of the ordering of things inside manipulate!)
2) The RMagick method to eventually pass these options to (Image::read) does not seem to work as advertised wrt. the block given to it. This would require some more digging into. 

So feel free to open an issue on Github if this is causing you problems, otherwise I'll just leave it at this. 

/Jacob
Reply all
Reply to author
Forward
0 new messages