Reputation: 285
I'm trying to resize on disk an attached image after saving it using Action Text.
I found this:
Rails6 resize uploaded images with Action Text & Active Storage
that only shows the resized image, but it's same size on disk.
After much searching on the Internet, I did this:
Get Path of blob file:
image_file_path = ActiveStorage::Blob.service.send(:path_for, blob.key)
Create an image object from that path of file:
image = MiniMagick::Image.read(File.binread(image_file_path))
Apply changes on image:
ImageProcessing::MiniMagick.source(image)
.resize_to_fit(width, height)
.call(destination: image_file_path)
Now, the attached image is resized, but metadata is wrong, so an integrity error is shown when it try to show the image.
The real new data is:
Any suggest?
Thanks!
Upvotes: 1
Views: 40