Page 1 of 1

Resized File Has Smaller Resolution But Much Larger Size

Posted: 2010-04-29T11:33:36-07:00
by dhead
I'm using RMagick for this.

I'm resizing JPEGs that were saved via Photoshop's "Save for web" with a quality of 10. When I resize the image to one with a smaller resolution the resulting file is much larger than the original.

Code: Select all

[jkat@localhost resize-test]$ cat resize.rb 
#!/usr/bin/ruby
require 'RMagick'

img = Magick::ImageList.new(ARGV.shift).first
img.change_geometry("1000x") do |cols, rows, i|
  i.resize!(cols, rows) 
  i.write('A.jpg')          
end

[jkat@localhost resize-test]$ !.
./resize.rb product-10.jpg 

[jkat@localhost resize-test]$ !iden
identify product-10.jpg A.jpg 
product-10.jpg JPEG 1486x2000 1486x2000+0+0 8-bit DirectClass 220kb 
A.jpg[1] JPEG 1000x1346 1000x1346+0+0 8-bit DirectClass 443kb 
I tried playing around with:

Code: Select all

img.distort(Magick::ScaleRotateTranslateDistortion, ...)
but it did not help.

How can I reduce the resized image's size. I'd hope it could be smaller the than original.

Also

Code: Select all

identify -verbose product-10.jpg A.jpg
produce nearly identical output (except for APP12 profile in product).

Re: Resized File Has Smaller Resolution But Much Larger Size

Posted: 2010-04-29T12:04:56-07:00
by el_supremo
I think what is happening is that ImageMagick by default uses a quality of 85 (best is 100) when it saves a JPG so you may be saving the smaller image at a much higher quality than the original. I don't know how to do this with RMagick but just before you write the JPG you need to set the JPG compression quality to a lower value. There seems to be an example of specifying the compression here:
http://www.imagemagick.org/RMagick/doc/ ... ompressing

Pete

Re: Resized File Has Smaller Resolution But Much Larger Size

Posted: 2010-04-29T15:18:16-07:00
by dhead
Yes that was it, thanks. A pretty obvious solution but the docs (bundled with RMagick gem) are lacking.