# RMagick Image Optimize

**URL:** <https://www.ruby-forum.com/t/rmagick-image-optimize/83193>\
**Category:** Ruby\
**Created:** [March 17, 2006, 3:49pm UTC](https://www.ruby-forum.com/t/rmagick-image-optimize/83193 "2006-03-17T15:49:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 17, 2006, 3:49pm UTC](https://www.ruby-forum.com/t/rmagick-image-optimize/83193/1 "2006-03-17T15:49:58Z")

</div>

I’m new to RMagick and am looking for how you can set the optimization  
on a jpeg image. Can someone point me in the right direction?

Thanks!  
Tom

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 17, 2006, 5:00pm UTC](https://www.ruby-forum.com/t/rmagick-image-optimize/83193/2 "2006-03-17T17:00:21Z")

</div>

If by “optimization” you mean compression, see here:  
[http://www.simplesystems.org/RMagick/doc/comtasks.html#compressing](http://www.simplesystems.org/RMagick/doc/comtasks.html#compressing)

If you mean color reduction, see here:  
[http://www.simplesystems.org/RMagick/doc/image3.html#quantize](http://www.simplesystems.org/RMagick/doc/image3.html#quantize)

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 17, 2006, 10:05pm UTC](https://www.ruby-forum.com/t/rmagick-image-optimize/83193/3 "2006-03-17T22:05:58Z")

</div>

Thanks! The compession is definitely what I am looking for. I’m  
trying to use it dynamically when the image is rendered to a Rails web  
page. Currently, I am using the follwoing to render the image:

send\_data myimage.to\_blob, :disposition =\> ‘inline’, :type =\>  
‘image/jpg’

I tried using myimage.quality = 50, but it looks like that can only be  
done on a write. Is there a way for me to set the quality when  
rendering the image? Sorry if this is newbie stuff!

–Tom

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 17, 2006, 11:34pm UTC](https://www.ruby-forum.com/t/rmagick-image-optimize/83193/4 "2006-03-17T23:34:10Z")

</div>

TomRossi7 wrote:

> –Tom

quality works as an option to the to\_blob method, too. To change the  
compression level you have to specify quality as a optional argument to  
the to\_blob or write method. I don’t know how you’d do that in a Rails  
context. Perhaps a Rails expert will know.
