11

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

Community
  • 1
  • 1
tchret
  • 142
  • 2
  • 10

2 Answers2

4

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.

Aleksei Matiushkin
  • 119,336
  • 10
  • 100
  • 160
0

Is this for a website user upload? If it is, you would probably be best using CSS to turn the image into a circle, it would save a lot of server processing and if you feel that in the future you would like to revert back to a square image, it's a lot easier than individually changing the pictures back to the square versions, it's maybe just one line of CSS code.

Alex Ander
  • 1,430
  • 12
  • 19
  • 1
    Hi Alex, in my case CSS has no impact. In the same method I get a square image from GitHub, I round it and insert it in an other image, to get a personalized thumbnail – tchret Apr 19 '15 at 10:45