Resized File Has Smaller Resolution But Much Larger Size

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
dhead

Resized File Has Smaller Resolution But Much Larger Size

Post 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).
el_supremo
Posts: 1015
Joined: 2005-03-21T21:16:57-07:00

Re: Resized File Has Smaller Resolution But Much Larger Size

Post 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
Sorry, my ISP shutdown all personal webspace so my MagickWand Examples in C is offline.
See my message in this topic for a link to a zip of all the files.
dhead

Re: Resized File Has Smaller Resolution But Much Larger Size

Post by dhead »

Yes that was it, thanks. A pretty obvious solution but the docs (bundled with RMagick gem) are lacking.
Post Reply