views:

112

answers:

1

I need to resize an image in rmagick from its current size to a fixed width to a width of 300 without losing image quality. Currently I am doing following for a jpg image

 if previewImage.columns > 300
       previewImage.change_geometry!("300x") { |cols, rows, img|
           img.resize!(cols, rows)
       }
   end

am not sure if this the best way as I am losing sharpness in the resulting image. I want to be able to resize by losing the least amount of image quality.

I know there are filters and compression techniques: JPG JPEGCompression, LosslessJPEGCompression

but don't know which would provide the best result or could i convert the image to png and then resize?

+2  A: 

The conversion to PNG would be lossless. Resizing will always imply some loss in quality (you can try out the various image magick resize filters to see which one is best for your images... there really is no "best" one, that's why they let you choose. If the images you're dealing with are generally the same though, you should be able to pick an optimal one just by experimenting. Conversion from PNG back to JPG would imply more loss, so I would keep the image at PNG if you do go that route.

cam
thanks, will go ahead with some experiments..
Anand