Monday, March 17, 2008

How to compress image file in RMagick

Normally, you compress the image file by setting quality of image object to less than 100 percent.

img.write("myimage.jpg") { self.quality = 50 }

However, this usually not always works because suppose you have one big jpeg file (3000x1000) and you want to crop it into 250x250 dimension per each. Therefore, all of your crop files added up together should be less than the original file size. Somehow, this won't be true because the original file contains image profile so when you crop it all of crop files also contain this image profile. This is a problem that your crop files added up together are bigger than the original file. The solution of this I found in http://thinkingrails.blogspot.com/2007/07/compression-in-rmagick.html to remove image profile. Using either image.profile!("*", nil), delete_profile("*"), or image.strip! to remove all of these meta data because we don't need them in thumbnail image. Thanks to Arunkumar.

4 comments:

chamnap said...

Thanks for that. Keep up viewing my blog.

Anonymous said...

You made some nice points there. I did a search on the subject matter and found mainly people will consent with your blog..

Anonymous said...

top [url=http://www.001casino.com/]online casino[/url] brake the latest [url=http://www.realcazinoz.com/]online casino[/url] unshackled no deposit hand-out at the leading [url=http://www.baywatchcasino.com/]casino games
[/url].

yanmaneee said...

air jordan
golden goose
golden goose sneakers
hermes belt
off white jordan 1
birkin bag
jordan retro
louboutin
supreme clothing
adidas nmd

Subscribe in a Reader