Skip to content

Instantly share code, notes, and snippets.


zetter/random slicer

Created Jun 18, 2010
What would you like to do?
#! /usr/bin/ruby
# Saves two random and contiguous cropped images from a larger image
# Written so an image that is too big can be displayed on a dual screen desktop
IMAGE_NAME = "file_small.png"
IMAGE_WIDTH, IMAGE_HEIGHT =[0x10..0x18].unpack('NN')
# # For non-pngs:
# IMAGE_WIDTH, IMAGE_HEIGHT = [12304, 8605]
CROP_WIDTH, CROP_HEIGHT = [1920, 1200]
crop = lambda {|x, y, output_name| `convert -crop #{CROP_WIDTH}x#{CROP_HEIGHT}+#{x}+#{y} #{IMAGE_NAME} #{output_name}.png`}
x = rand(IMAGE_WIDTH - CROP_WIDTH * 2)
y = rand(IMAGE_HEIGHT - CROP_HEIGHT), y, 'left') + 1920, y, 'right')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment