Yes, there is a way to do this.
Reset the metadata "data:image/jpeg;base64," from the input line and then decode it using the Base64.decode64 method. You will get a binary blob. Direct this blob to MiniMagick::Image.read . ImageMagick is smart enough to guess all the metadata for you. Then process the image using the 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'
source share