30 lines
749 B
Ruby
Executable File
30 lines
749 B
Ruby
Executable File
#!/usr/bin/env ruby
|
|
|
|
def extract(input:, size:, offsets:, output: "/tmp/out.png")
|
|
`magick #{input} -crop #{size.map(&:to_s).join("x")}+#{offsets.map(&:to_s).join("+")} #{output}`
|
|
end
|
|
|
|
image_size = 200
|
|
image_plus_border_heigh = image_size + 44
|
|
image_plus_border_width = image_size + 46
|
|
init_offsets = [20, 180]
|
|
images_offsets = 3.times.flat_map do |x|
|
|
3.times.map do |y|
|
|
[
|
|
init_offsets[0] + x * image_plus_border_width,
|
|
init_offsets[1] + y * image_plus_border_heigh,
|
|
]
|
|
end
|
|
end
|
|
|
|
images_offsets.each_with_index do |offsets, index|
|
|
output = "crop-#{File.basename(ARGV[0], "png")}-#{index}.png"
|
|
extract(
|
|
input: ARGV[0],
|
|
output: output,
|
|
size: [image_size, image_size],
|
|
offsets: offsets,
|
|
)
|
|
puts output
|
|
end
|