Versionning based on original image quality

I am versionning users files into a 85% quality JPEG with Shrine and VIPS.
Though it’s not the most efficient in my case if my user submits an image with a quality lower than 85%: the resulting image will be heavier but won’t have a better quality.

A good fix would be to retrieve the original image quality value and comparing it against the quality used for versionning ?

With ImageMagick we can do an “identify” but it returns more information than just the quality. (Maybe I could try to parse this string though)
Has someone done something similar ?

EDIT : MiniMagick seems to have easy access to Image magick identify function
I tried the follow :
orig_quality = ImageProcessing::MiniMagick.source(original).data["quality"].to_i
but I get error

2020-06-25T17:48:41.247Z pid=10705 tid=goweisxop WARN: TypeError: can’t convert ImageProcessing::Builder to Integer (ImageProcessing::Builder#to_int gives ImageProcessing::Builder)

(I am trying to use the original image quality above as versionning dimension so I know it works …)

I have found the solution.
I have tried to require MiniMagick directly:
changed require "image_processing/mini_magick" to require "mini_magick"
and also realised that original was not an image but a Shrine file :

2020-06-26T09:21:51.074Z pid=713 tid=goq226o6x WARN: NoMethodError: undefined method `data’ for #<File:/tmp/shrine20200626-713-8p1t27.jpg (closed)>

Then instead of calling original I called the attachment context[:record].image

and the below works :
orig_quality = MiniMagick::Image.open(context[:record].image).data["quality"].to_i

Though it slows down a bit the VIPS processing (probably because I play with 2 gems instead of VIPs only). If someone knows a faster solution I am all ears… other wise I am happy !