Rails MiniMagick How to get info: value?

40 views Asked by At

I want to remove black bars from the image and found that bash script that works well

margin=$(convert input.jpg -fuzz 10% -set page "%[@]" -format "%[fx:h-page.height-page.y]" info:)
magick input.jpg -gravity South -chop 0x$margin -gravity North -chop 0x$margin output.jpg
convert input.jpg -fuzz 10% -set page "%[@]" -format "%[fx:h-page.height-page.y]" info:

returns for example 140, it is a pixel size of black bar But I can't this value using ruby interface

convert = MiniMagick::Tool::Convert.new
convert << "test.jpg"
convert.fuzz("10%")
convert.set('page "%[@]"')
convert.format("%[fx:h-page.height-page.y]")
convert.call

This command returns

test.jpg[0] JPEG 1920x1080 1920x1080+0+0 8-bit sRGB 57180B 0.010u 0:00.018\n%[fx:h-page.height-page.y][1] JPEG 1920x1080 1920x1080+0+0 8-bit sRGB 47180B 0.010u 0:00.009

How to get back margin value? This string doesn't contain 140

If I call

convert.command.join ' '

I get

convert test.jpg -fuzz 10% -set page %[@] -format %[fx:h-page.height-page.y]
1

There are 1 answers

0
Ivan On
convert = MiniMagick::Tool::Convert.new
convert << "test.jpg"
convert.fuzz("10%")
convert.set 'page', '%[@]'
convert.format '%[fx:h-page.height-page.y]'
convert << "info:"
convert.call

This returns correct value. Thanks to chatgpt for help for argument positioning