Skip to content

Instantly share code, notes, and snippets.

@zetter
Created June 18, 2010 09:22
Show Gist options
  • Save zetter/443432 to your computer and use it in GitHub Desktop.
Save zetter/443432 to your computer and use it in GitHub Desktop.
#! /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