Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 !!

like image 860
tchret Avatar asked Apr 08 '15 18:04

tchret


1 Answers

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.

like image 66
Aleksei Matiushkin Avatar answered Nov 18 '22 04:11

Aleksei Matiushkin