Class: Image
Constant Summary
collapse
- @@search =
false
Constants inherited
from Zarchitect
Zarchitect::ASSETDIR, Zarchitect::ASSETSDIR, Zarchitect::BUILDIR, Zarchitect::CONFIGDIR, Zarchitect::DEBUGSDIR, Zarchitect::DRAFTDIR, Zarchitect::FILEDIR, Zarchitect::FILESDIR, Zarchitect::HTMLDIR, Zarchitect::LAYOUTDIR, Zarchitect::NODEDIR, Zarchitect::SHARESDIR, Zarchitect::VERSION
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Zarchitect
#main, #rss
Constructor Details
#initialize(path, f) ⇒ Image
+++++++++++++++++++++++++++++
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
|
# File 'lib/zarchitect/image.rb', line 16
def initialize(path, f)
@thumbf = f
@path = path
unless @thumbf
@url = path.clone
@url[0] = "/"
else
@url = path[(HTMLDIR.length)..-1]
end
@dimensions = Point.new(0,0)
arr = %x{identify #{@path}}.split(" ")
dim = arr[2].split("x")
@dimensions.x = dim[0].to_i
@dimensions.y = dim[1].to_i
@size = File.size(path)
@type = arr[1].clone
if @size > Zarchitect.conf.image_limit.to_f.mib_to_bytes
GPI.print "Error: File #{path} too large "\
"(#{@size.bytes_to_mib.to_f.round(2)}MiB)."\
" Allowed size: #{Zarchitect.conf.image_limit.to_f.mb_to_mib.round(2)}"
GPI.quit
end
strip_exif unless @thumbf
end
|
Instance Attribute Details
#dimensions ⇒ Object
Returns the value of attribute dimensions.
2
3
4
|
# File 'lib/zarchitect/image.rb', line 2
def dimensions
@dimensions
end
|
#size ⇒ Object
Returns the value of attribute size.
2
3
4
|
# File 'lib/zarchitect/image.rb', line 2
def size
@size
end
|
#thumbl_f=(value) ⇒ Object
Sets the attribute thumbl_f
3
4
5
|
# File 'lib/zarchitect/image.rb', line 3
def thumbl_f=(value)
@thumbl_f = value
end
|
#thumbs_f=(value) ⇒ Object
Sets the attribute thumbs_f
3
4
5
|
# File 'lib/zarchitect/image.rb', line 3
def thumbs_f=(value)
@thumbs_f = value
end
|
#type ⇒ Object
Returns the value of attribute type.
2
3
4
|
# File 'lib/zarchitect/image.rb', line 2
def type
@type
end
|
Class Method Details
.find(k, v) ⇒ Object
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/zarchitect/image.rb', line 124
def self.find(k, v)
@@search = true
GPI.print "Looking for img: #{v}", GPI::CLU.check_option('v')
ObjectSpace.each_object(ImageSet) do |set|
str = set.orig.send(k)
if str == v
GPI.print "Image found", GPI::CLU.check_option('v')
@@search = false
return set
end
end
@@search = false
nil
end
|
.is_valid?(filename) ⇒ Boolean
120
121
122
|
# File 'lib/zarchitect/image.rb', line 120
def self.is_valid?(filename)
[".png",".gif",".jpg",".jpeg",".bmp"].include?(File.extname(filename))
end
|
Instance Method Details
#create_thumbnail(path, thumb_x, thumb_y) ⇒ Object
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
|
# File 'lib/zarchitect/image.rb', line 82
def create_thumbnail(path, thumb_x, thumb_y)
GPI.print "attempting to create thumbnail #{path}",
GPI::CLU.check_option('v')
return false if path.include?("/#{SHARESDIR}/")
x = @dimensions.x
y = @dimensions.y
if x <= thumb_x && y <= thumb_y
GPI.print "abort thumbnail creation. No thumbnail #{thumb_x}x"\
"#{thumb_y} necessary", GPI::CLU.check_option('v')
return false
end
if ["PNG", "GIF"].include?(@type)
while true do
x = x/2
y = y/2
break if x <= thumb_x && y <= thumb_y
end
if x < 1 || y < 1
GPI.print "failed to create #{path}: invalid downsizing",
GPI::CLU.check_option('v')
return false
end
command = "convert #{@path} -scale #{x}x#{y} #{path}"
GPI.print "#{command}", GPI::CLU.check_option('v')
o = %x{#{command}}
GPI.print o, GPI::CLU.check_option('v')
return true
else
command = "convert #{@path} -resize #{thumb_x}x#{thumb_y} #{path}"
GPI.print "#{command}", GPI::CLU.check_option('v')
o = %x{#{command}}
GPI.print o, GPI::CLU.check_option('v')
return true
end
end
|
#larger_than_thumb_large? ⇒ Boolean
77
78
79
80
|
# File 'lib/zarchitect/image.rb', line 77
def larger_than_thumb_large?
@dimensions.x > Zarchitect.conf.thumbl[0].to_i ||
@dimensions.y > Zarchitect.conf.thumbl[1].to_i
end
|
#larger_than_thumb_small? ⇒ Boolean
72
73
74
75
|
# File 'lib/zarchitect/image.rb', line 72
def larger_than_thumb_small?
@dimensions.x > Zarchitect.conf.thumbs[0].to_i ||
@dimensions.y > Zarchitect.conf.thumbs[1].to_i
end
|
#thumb_large? ⇒ Boolean
57
58
59
|
# File 'lib/zarchitect/image.rb', line 57
def thumb_large?
@thumbl_f
end
|
#thumb_small? ⇒ Boolean
53
54
55
|
# File 'lib/zarchitect/image.rb', line 53
def thumb_small?
@thumbs_f
end
|
#url ⇒ Object
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/zarchitect/image.rb', line 61
def url
@url
end
|