/
image_maker.rb
executable file
·71 lines (59 loc) · 1.5 KB
/
image_maker.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env ruby
require 'rubygems'
require 'RMagick'
include Magick
# Creates a composite from four photos
# [ A ] [ B ] [ C ] [ D ]
# gapimagegapimagegapimagega
# [ A ] [ B ] [ C ] [ D ]
class BoothPhoto
IMAGE_SIZE = [524, 349] # width, height, in pixels
COMPOSITE_SIZE = [2400, 1200] # columns, rows, in pixels
BORDER = 38 # 76 pixels total, bringing image to 425x600 or (1.43in x 2in @300dpi)
GAP_HEIGHT = 350
def initialize(paths = [])
@photos = []
@comp = Image.new( COMPOSITE_SIZE )
collect_photos( paths )
add_photos_to_composite
end
def grayscale!
@comp = @comp.quantize(256,GRAYColorspace)
end
def oil_paint!
@comp = @comp.oil_paint(1.0)
end
def sepia!
@comp = @comp.sepiatone()
end
def display
@comp.display
end
def save(file_name)
@comp.write(file_name)
end
private
def collect_photos(paths)
paths.each do |path|
@photos << ImageList.new(path).thumbnail!(IMAGE_SIZE).border!(BORDER, BORDER, "#f0f0ff")
end
end
def add_photos_to_composite
add_row(0)
add_gap
add_row(IMAGE_SIZE[1] + (BORDER * 2) + GAP_HEIGHT)
end
def add_row(y_offset)
offset = 0
@photos.each do |photo|
@comp.composite!( photo, NorthWestGravity , offset , y_offset, AtopCompositeOp )
offset += photo.columns
end
end
end
b = BoothPhoto.new(%w(IMG_9671.JPG IMG_9672.JPG IMG_9673.JPG IMG_9674.JPG))
b.grayscale!
#b.sepia!
b.oil_paint!
b.save("photo_composite.jpg")
exit