0

I am trying to resize an image and reduce the quality of an image pulled from a database and be able to save it back into the database at the reduced size.

So far, I am trying the following RMagick methods:

image = Image.from_blob(origImage.data).first do
        self.format = "png"
      end
      image.resize_to_fit!(width)
      image.quality = 60
      newImage = image.to_blob

But the value of image.quality has no implact on the size of data from to_blob.

Am I doing this correctly?

Stefan Dunn
  • 5,363
  • 7
  • 48
  • 84

1 Answers1

1

Try putting the quality argument on the to_blob method instead.

# image.quality = 60 # ignore this
newImage = image.to_blob { self.quality = 60 }

You're probably outputting the same format as origImage there -- format doesn't appear to work in from_blob. I had to specifically call it after the from_blob line to set the PNG format.

image = Magick::Image.from_blob(origImage.data).first do
#    self.format = 'PNG'
end
image.format = 'PNG'
rjp
  • 1,942
  • 12
  • 14