Created
April 29, 2023 03:46
-
-
Save ramses-lopez/72e27f7edeba73c811771f200e9684ed to your computer and use it in GitHub Desktop.
Use ruby-vips to crop one image into smaller images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'vips' | |
input_image = Vips::Image.new_from_file('all_pics.webp') | |
x = 0 | |
y = 0 | |
width = 100 | |
height = 100 | |
gap = 28 | |
(0..6).to_a.each do |i| | |
(0..6).to_a.each do |j| | |
puts "Cropping image #{i} #{j}" | |
x = j * (width + gap) | |
y = i * (height + gap) | |
puts "x: #{x}, y: #{y}" | |
input_image | |
.crop(x, y, width, height) | |
.write_to_file("cropped_pics/#{i}_#{j}.webp") | |
puts "Image #{i} #{j} cropped!\n\n" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment