Class: Shellfie::ImageMagickCommandBuilder
- Inherits:
-
Object
- Object
- Shellfie::ImageMagickCommandBuilder
- Defined in:
- lib/shellfie/image_magick_command_builder.rb
Class Method Summary collapse
- .canvas(convert, width:, height:, background:) ⇒ Object
- .circle(convert, center_x, center_y, radius) ⇒ Object
- .clear_region(convert) ⇒ Object
- .composite_over(convert) ⇒ Object
- .convert(&block) ⇒ Object
- .draw(convert, command) ⇒ Object
- .line(convert, x1, y1, x2, y2) ⇒ Object
- .lines(convert, lines) ⇒ Object
- .output(convert, path, format: nil) ⇒ Object
- .output_path(path, format:) ⇒ Object
- .point(convert, x, y) ⇒ Object
- .rectangle(convert, x1, y1, x2, y2) ⇒ Object
- .rectangles(convert, rectangles) ⇒ Object
- .region(convert, x:, y:, width:, height:) ⇒ Object
- .round_rectangle(convert, x1, y1, x2, y2, radius) ⇒ Object
Class Method Details
.canvas(convert, width:, height:, background:) ⇒ Object
12 13 14 15 |
# File 'lib/shellfie/image_magick_command_builder.rb', line 12 def canvas(convert, width:, height:, background:) convert.size "#{width}x#{height}" convert << background end |
.circle(convert, center_x, center_y, radius) ⇒ Object
53 54 55 |
# File 'lib/shellfie/image_magick_command_builder.rb', line 53 def circle(convert, center_x, center_y, radius) draw(convert, "circle #{center_x},#{center_y} #{center_x + radius},#{center_y}") end |
.clear_region(convert) ⇒ Object
65 66 67 |
# File 'lib/shellfie/image_magick_command_builder.rb', line 65 def clear_region(convert) convert << "+region" end |
.composite_over(convert) ⇒ Object
69 70 71 72 |
# File 'lib/shellfie/image_magick_command_builder.rb', line 69 def composite_over(convert) convert.compose "over" convert.composite end |
.convert(&block) ⇒ Object
8 9 10 |
# File 'lib/shellfie/image_magick_command_builder.rb', line 8 def convert(&block) MiniMagick.convert(&block) end |
.draw(convert, command) ⇒ Object
25 26 27 |
# File 'lib/shellfie/image_magick_command_builder.rb', line 25 def draw(convert, command) convert.draw command end |
.line(convert, x1, y1, x2, y2) ⇒ Object
43 44 45 |
# File 'lib/shellfie/image_magick_command_builder.rb', line 43 def line(convert, x1, y1, x2, y2) draw(convert, "line #{x1},#{y1} #{x2},#{y2}") end |
.lines(convert, lines) ⇒ Object
47 48 49 50 51 |
# File 'lib/shellfie/image_magick_command_builder.rb', line 47 def lines(convert, lines) return if lines.empty? draw(convert, lines.map { |line| "line #{line[:x1]},#{line[:y1]} #{line[:x2]},#{line[:y2]}" }.join(" ")) end |
.output(convert, path, format: nil) ⇒ Object
17 18 19 |
# File 'lib/shellfie/image_magick_command_builder.rb', line 17 def output(convert, path, format: nil) convert << output_path(path, format: format || File.extname(path).delete_prefix(".")) end |
.output_path(path, format:) ⇒ Object
21 22 23 |
# File 'lib/shellfie/image_magick_command_builder.rb', line 21 def output_path(path, format:) format == "apng" ? "apng:#{path}" : path end |
.point(convert, x, y) ⇒ Object
57 58 59 |
# File 'lib/shellfie/image_magick_command_builder.rb', line 57 def point(convert, x, y) draw(convert, "point #{x},#{y}") end |
.rectangle(convert, x1, y1, x2, y2) ⇒ Object
29 30 31 |
# File 'lib/shellfie/image_magick_command_builder.rb', line 29 def rectangle(convert, x1, y1, x2, y2) draw(convert, "rectangle #{x1},#{y1} #{x2},#{y2}") end |
.rectangles(convert, rectangles) ⇒ Object
33 34 35 36 37 |
# File 'lib/shellfie/image_magick_command_builder.rb', line 33 def rectangles(convert, rectangles) return if rectangles.empty? draw(convert, rectangles.map { |rect| "rectangle #{rect[:x1]},#{rect[:y1]} #{rect[:x2]},#{rect[:y2]}" }.join(" ")) end |
.region(convert, x:, y:, width:, height:) ⇒ Object
61 62 63 |
# File 'lib/shellfie/image_magick_command_builder.rb', line 61 def region(convert, x:, y:, width:, height:) convert.region "#{width}x#{height}+#{x}+#{y}" end |
.round_rectangle(convert, x1, y1, x2, y2, radius) ⇒ Object
39 40 41 |
# File 'lib/shellfie/image_magick_command_builder.rb', line 39 def round_rectangle(convert, x1, y1, x2, y2, radius) draw(convert, "roundrectangle #{x1},#{y1} #{x2},#{y2} #{radius},#{radius}") end |