开发者

resize image in ruby on rails using rmagick without losing quality

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 res开发者_C百科ize 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?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜