Skip to content

Instantly share code, notes, and snippets.

@zetter zetter/random slicer
Created Jun 18, 2010

Embed
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 = IO.read(IMAGE_NAME)[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)
crop.call(x, y, 'left')
crop.call(x + 1920, y, 'right')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.