File: draw_lines.rb

package info (click to toggle)
ruby-vips 2.1.4-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,164 kB
  • sloc: ruby: 3,530; makefile: 3
file content (30 lines) | stat: -rwxr-xr-x 754 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/usr/bin/ruby

require "vips"

# load and stream into memory
image = Vips::Image.new_from_file(ARGV[0], access: :sequential).copy_memory

starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)

lines = image
(0..1).step 0.01 do |i|
  lines = lines.draw_line 255, lines.width * i, 0, 0, lines.height * (1 - i)
end

ending = Process.clock_gettime(Process::CLOCK_MONOTONIC)
puts "non-destructive took #{ending - starting}s"

starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)

lines = image
lines = lines.mutate do |x|
  (0..1).step 0.01 do |i|
    x.draw_line! 255, x.width * i, 0, 0, x.height * (1 - i)
  end
end

ending = Process.clock_gettime(Process::CLOCK_MONOTONIC)
puts "mutate took #{ending - starting}s"

lines.write_to_file ARGV[1]