Search code examples
rubyimagemagickminimagick

MiniMagick : Cut circle out of square image


I need to transform a square image in circle image with MiniMagick.

I know there is a way with ImageMagick:

convert -size 300x300 xc:transparent -fill "image.png" -draw "circle 240,90 290,90" -crop 100x100+190+40 +repage circle1.png

I've tried to translate :

img.combine_options do |c|
  c.draw "circle 240,90 290,90"
  c.crop "100x100+190+40"
  c.repage.+
end

I get this stuff, a black circle with my big nose as background image :

enter image description here

if anyone know how to translate this properly... please !!


Solution

  • Just use Metal:

    require 'mini_magick'
    
    MiniMagick::Tool::Convert.new do |cvrt|
     cvrt.size '300x300'
     cvrt << 'xc:transparent'
     cvrt.fill 'image.png'
     cvrt.draw "circle 240,90 290,90"
     cvrt.crop '100x100+190+40'
     cvrt.repage.+
     cvrt << 'circle.png'
    end
    

    I personally never try to remember all this domestic method names and always use the metal core approach.