Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /homepages/11/d274290037/htdocs/serabe/wp-content/plugins/jetpack/_inc/lib/class.media-summary.php on line 77

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /homepages/11/d274290037/htdocs/serabe/wp-content/plugins/jetpack/_inc/lib/class.media-summary.php on line 87
RMagick: Dibujar con patrones | Conecto ergo sum.
Warning: Use of undefined constant user_level - assumed 'user_level' (this will throw an Error in a future version of PHP) in /homepages/11/d274290037/htdocs/serabe/wp-content/plugins/ultimate-google-analytics/ultimate_ga.php on line 524

Warning: count(): Parameter must be an array or an object that implements Countable in /homepages/11/d274290037/htdocs/serabe/wp-includes/post-template.php on line 284

Warning: Use of undefined constant user_level - assumed 'user_level' (this will throw an Error in a future version of PHP) in /homepages/11/d274290037/htdocs/serabe/wp-content/plugins/ultimate-google-analytics/ultimate_ga.php on line 524

RMagick: Dibujar con patrones


Warning: Illegal string offset 'language' in /homepages/11/d274290037/htdocs/serabe/wp-content/plugins/igsyntax-hiliter/classes/frontend.php on line 510

Warning: ksort() expects parameter 1 to be array, string given in /homepages/11/d274290037/htdocs/serabe/wp-content/plugins/igsyntax-hiliter/classes/frontend.php on line 513

Warning: Illegal string offset 'language' in /homepages/11/d274290037/htdocs/serabe/wp-content/plugins/igsyntax-hiliter/classes/frontend.php on line 510

Warning: ksort() expects parameter 1 to be array, string given in /homepages/11/d274290037/htdocs/serabe/wp-content/plugins/igsyntax-hiliter/classes/frontend.php on line 513

Warning: Illegal string offset 'language' in /homepages/11/d274290037/htdocs/serabe/wp-content/plugins/igsyntax-hiliter/classes/frontend.php on line 510

Warning: ksort() expects parameter 1 to be array, string given in /homepages/11/d274290037/htdocs/serabe/wp-content/plugins/igsyntax-hiliter/classes/frontend.php on line 513

Warning: Use of undefined constant user_level - assumed 'user_level' (this will throw an Error in a future version of PHP) in /homepages/11/d274290037/htdocs/serabe/wp-content/plugins/ultimate-google-analytics/ultimate_ga.php on line 524

Una interesante cualidad de la clase Draw de RMagick es la posibilidad de definir patrones a través del método pattern.

En primer lugar, lo básico:

  1. require 'rubygems'
  2. require 'RMagick'
  3.  
  4. include Magick

Ahora definamos el patrón. Para ello, necesitamos cinco parámetros, el nombre, dos números que recomiendo ponerlos a cero (después de unas cuantas pruebas, no he notado diferencias notables) y después las dimensiones del patrón.

  1. draw = Draw.new
  2.  
  3. draw.pattern('circles', 0, 0, 10, 10) do
  4.   draw.stroke 'none'
  5.   draw.fill 'red'
  6.   draw.rectangle 0, 0, 10, 10
  7.   draw.stroke 'LightGreen'
  8.   draw.fill 'blue'
  9.   draw.circle 5, 5, 5, 0
  10. end

Ya, por último, dibujamos un cuadrado y lo plasmamos en una imagen de 300×300.

  1. draw.stroke 'circles'
  2. draw.stroke_width 25
  3.  
  4. draw.fill 'none'
  5.  
  6. draw.polygon 150,0, 300,150, 150,300, 0,150
  7.  
  8. img = Image.new 300, 300
  9.  
  10. draw.draw img
  11.  
  12. img.write 'pattern.jpg'

Obteniéndose el siguiente resultado:

Dibujo con patrón como brocha
Dibujo con patrón como brocha

1 thought on “RMagick: Dibujar con patrones

  1. Pingback:
    Warning: Use of undefined constant user_level - assumed 'user_level' (this will throw an Error in a future version of PHP) in /homepages/11/d274290037/htdocs/serabe/wp-content/plugins/ultimate-google-analytics/ultimate_ga.php on line 524
    Websites tagged "rmagick" on Postsaver

Leave a Comment


Warning: Use of undefined constant user_level - assumed 'user_level' (this will throw an Error in a future version of PHP) in /homepages/11/d274290037/htdocs/serabe/wp-content/plugins/ultimate-google-analytics/ultimate_ga.php on line 524

Warning: Use of undefined constant user_level - assumed 'user_level' (this will throw an Error in a future version of PHP) in /homepages/11/d274290037/htdocs/serabe/wp-content/plugins/ultimate-google-analytics/ultimate_ga.php on line 524