Yes, there is a way to do that.
Strip metadata "data:image/jpeg;base64,"
from your input string and then decode it with Base64.decode64
method. You'll get binary blob. Feed that blob to MiniMagick::Image.read
. ImageMagick is smart enough to guess all metadata for you. Then process the image with mini_magick
methods as usual.
require 'base64'
uploaded_io = "data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2....."
metadata = "data:image/jpeg;base64,"
base64_string = uploaded_io[metadata.size..-1]
blob = Base64.decode64(base64_string)
image = MiniMagick::Image.read(blob)
image.write 'image.jpeg'
# Retrieve attributes
image.type # "JPEG"
image.mime_type # "image/jpeg"
image.size # 458763
image.width # 640
image.height # 480
image.dimensions # [640, 480]
# Save in other format
image.format 'png'
image.write 'image.png'