-
Notifications
You must be signed in to change notification settings - Fork 0
/
dreamscreen.rb
121 lines (103 loc) · 2.75 KB
/
dreamscreen.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
require 'RMagick'
include Magick
module DreamScreen
BASE = File.expand_path(File.dirname(__FILE__))
OUT_DIR_PATH = BASE + "/public/images/final"
BG_DIR_PATH = BASE + "/public/images/bg"
SCREEN_DIR_PATH = BASE + "/public/images/screened"
RAW_DIR_PATH = BASE + "/public/images/raw"
def self.get_filenames(dir)
fnames = []
sorted_files = Dir.entries(dir).sort_by{ |f| File.ctime(dir + "/" + f) }.reverse
sorted_files.each do |filename|
next if filename == "."
next if filename == ".."
fnames << filename
end
return fnames
end
=begin
def class ThumbnailManager
attr_accessor :thumb_fnames, :dir
def initialize(dir_path)
@dir = dir_path
@thumb_fnames = get_filenames(dir_path)
end
end
=end
#get images in directories
def self.raw_images
fnames = get_filenames(RAW_DIR_PATH)
return fnames
end
def self.screened_images
fnames = get_filenames(SCREEN_DIR_PATH)
return fnames
end
def self.bg_images
fnames = get_filenames(BG_DIR_PATH)
return fnames
end
def self.out_images
fnames = get_filenames(OUT_DIR_PATH)
return fnames
end
def self.remove_green(filename)
begin
il = ImageList.new
temp = ImageList.new
base = ImageList.new(RAW_DIR_PATH + "/" + filename)
#light 46f75f
light_green = '#46f75f'
#mid 249523
mid_green = '#249523'
#dark 1d6c1d
#dark_green = '#102d0f'
dark_green = '#184117'
#first pass
base.fuzz = 1700
temp << base.scale(0.25).opaque_channel(dark_green, mid_green)
#second pass
second_pass = temp.flatten_images
second_pass.fuzz = 12500
il << second_pass.opaque_channel(mid_green, light_green).opaque_channel(light_green, light_green).transparent(light_green, Magick::TransparentOpacity)
#puts il.inspect
final = il.cur_image
return final
rescue
puts "Caught exception: #{$!}"
return nil
end
end
def self.merge_background(filename, bg_fname)
begin
il = ImageList.new
base = ImageList.new(SCREEN_DIR_PATH + "/" + filename)
bg = ImageList.new(BG_DIR_PATH + "/" + bg_fname)
il << bg.resize_to_fill(base.columns, base.rows)
il << base.cur_image
return il.flatten_images
rescue
puts "Caught exception: #{$!}"
return nil
end
end
def self.save_image(filename, img)
begin
img.write(OUT_DIR_PATH + "/" + filename)
return true
rescue
puts "Caught exception: #{$!}"
return false
end
end
def self.save_screen(filename, img)
begin
img.write(SCREEN_DIR_PATH + "/" + filename)
return true
rescue
puts "Caught exception: #{$!}"
return false
end
end
end