bcms_tools 0.0.13 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/bcms_tools.gemspec +5 -5
- data/lib/bcms_tools/bcms_thumbnails.rb +378 -125
- data/lib/bcms_tools/form_helpers.rb +2 -2
- metadata +3 -3
data/Rakefile
CHANGED
@@ -11,7 +11,7 @@ begin
|
|
11
11
|
gem.homepage = "http://github.com/buzzware/bcms_tools"
|
12
12
|
gem.authors = ["buzzware"]
|
13
13
|
gem.add_dependency "buzzcore", ">= 0.3.2"
|
14
|
-
gem.add_dependency "paperclip", "= 2.1.
|
14
|
+
gem.add_dependency "paperclip", "= 2.3.1.1"
|
15
15
|
gem.add_dependency "browsercms"
|
16
16
|
gem.add_development_dependency "shoulda"
|
17
17
|
gem.files.include %w(
|
data/VERSION
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
0.0
|
1
|
+
0.1.0
|
2
2
|
|
data/bcms_tools.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{bcms_tools}
|
8
|
-
s.version = "0.0
|
8
|
+
s.version = "0.1.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["buzzware"]
|
12
|
-
s.date = %q{2010-04-
|
12
|
+
s.date = %q{2010-04-30}
|
13
13
|
s.description = %q{Tools for BrowserCms.}
|
14
14
|
s.email = %q{contact@buzzware.com.au}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -57,18 +57,18 @@ Gem::Specification.new do |s|
|
|
57
57
|
|
58
58
|
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
59
59
|
s.add_runtime_dependency(%q<buzzcore>, [">= 0.3.2"])
|
60
|
-
s.add_runtime_dependency(%q<paperclip>, ["= 2.1.
|
60
|
+
s.add_runtime_dependency(%q<paperclip>, ["= 2.3.1.1"])
|
61
61
|
s.add_runtime_dependency(%q<browsercms>, [">= 0"])
|
62
62
|
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
63
63
|
else
|
64
64
|
s.add_dependency(%q<buzzcore>, [">= 0.3.2"])
|
65
|
-
s.add_dependency(%q<paperclip>, ["= 2.1.
|
65
|
+
s.add_dependency(%q<paperclip>, ["= 2.3.1.1"])
|
66
66
|
s.add_dependency(%q<browsercms>, [">= 0"])
|
67
67
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
68
68
|
end
|
69
69
|
else
|
70
70
|
s.add_dependency(%q<buzzcore>, [">= 0.3.2"])
|
71
|
-
s.add_dependency(%q<paperclip>, ["= 2.1.
|
71
|
+
s.add_dependency(%q<paperclip>, ["= 2.3.1.1"])
|
72
72
|
s.add_dependency(%q<browsercms>, [">= 0"])
|
73
73
|
s.add_dependency(%q<shoulda>, [">= 0"])
|
74
74
|
end
|
@@ -1,8 +1,214 @@
|
|
1
|
+
# BEGIN Paperclip 2.3.1.1 fixes for funky filenames
|
2
|
+
|
3
|
+
Paperclip.class_eval do
|
4
|
+
|
5
|
+
def self.run cmd, params = "", expected_outcodes = 0
|
6
|
+
command = %Q[#{path_for_command(cmd)} #{params}] #.gsub(/\s+/, " ") # removed unnecessary(?) whitespace eating
|
7
|
+
command = "#{command} 2>#{bit_bucket}" if Paperclip.options[:swallow_stderr]
|
8
|
+
Paperclip.log(command) if Paperclip.options[:log_command]
|
9
|
+
output = `#{command}`
|
10
|
+
unless [expected_outcodes].flatten.include?($?.exitstatus)
|
11
|
+
raise Paperclip::PaperclipCommandLineError, "Error while running #{cmd}"
|
12
|
+
end
|
13
|
+
output
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
Paperclip::Geometry.class_eval do
|
19
|
+
def self.from_file file
|
20
|
+
file = file.path if file.respond_to? "path"
|
21
|
+
geometry = begin
|
22
|
+
srcpath = file.gsub('$','\$') # escaped $, other chars may need to be added here
|
23
|
+
Paperclip.run("identify", %Q[-format "%wx%h" "#{srcpath}"[0]])
|
24
|
+
rescue Paperclip::PaperclipCommandLineError
|
25
|
+
""
|
26
|
+
end
|
27
|
+
parse(geometry) ||
|
28
|
+
raise(Paperclip::NotIdentifiedByImageMagickError.new("#{file} is not recognized by the 'identify' command."))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# !!! must also fix /Library/Ruby/Gems/1.8/gems/paperclip-2.3.1.1/lib/paperclip/thumbnail.rb:54
|
33
|
+
# and put in lighthouse
|
34
|
+
Paperclip::Thumbnail.class_eval do
|
35
|
+
|
36
|
+
attr_accessor :basename # need access to basename so we can change it away from bizarre file names that cause problems. could auto generate better names here
|
37
|
+
|
38
|
+
def make
|
39
|
+
src = @file
|
40
|
+
dst = Tempfile.new([@basename, @format].compact.join("."))
|
41
|
+
dst.binmode
|
42
|
+
|
43
|
+
# The original used the following string construction, then removed whitespace ignoring
|
44
|
+
# the fact that the whitespace may be in a path
|
45
|
+
# Instead we now construct the string normally.
|
46
|
+
#command = <<-end_command
|
47
|
+
# #{ source_file_options }
|
48
|
+
# "#{ File.expand_path(src.path) }[0]"
|
49
|
+
# #{ transformation_command }
|
50
|
+
# "#{ File.expand_path(dst.path) }"
|
51
|
+
#end_command
|
52
|
+
srcpath = File.expand_path(src.path).gsub('$','\$') # escape $, more chars may need to be added
|
53
|
+
command = "#{ source_file_options } \"#{ srcpath }[0]\" #{ transformation_command } \"#{ File.expand_path(dst.path) }\""
|
54
|
+
|
55
|
+
begin
|
56
|
+
success = Paperclip.run("convert", command) #.gsub(/\s+/, " "))
|
57
|
+
rescue Paperclip::PaperclipCommandLineError
|
58
|
+
raise Paperclip::PaperclipError, "There was an error processing the thumbnail for #{@basename}" if @whiny
|
59
|
+
end
|
60
|
+
|
61
|
+
dst
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
|
66
|
+
# END Paperclip 2.3.1.1 fixes for funky filenames
|
67
|
+
|
68
|
+
module Buzzcore
|
69
|
+
module ImageUtils
|
70
|
+
|
71
|
+
module_function # this makes these methods callable as BcmsTools::PageHelper.method
|
72
|
+
|
73
|
+
def image_file_dimensions(aFilename)
|
74
|
+
if geomImage = Paperclip::Geometry.from_file(aFilename)
|
75
|
+
return geomImage.width,geomImage.height
|
76
|
+
else
|
77
|
+
return nil,nil
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
# see http://www.imagemagick.org/script/command-line-processing.php#geometry
|
82
|
+
#
|
83
|
+
# scale% Height and width both scaled by specified percentage.
|
84
|
+
# scale-x%xscale-y% Height and width individually scaled by specified percentages. (Only one % symbol needed.)
|
85
|
+
# width Width given, height automagically selected to preserve aspect ratio.
|
86
|
+
# xheight Height given, width automagically selected to preserve aspect ratio.
|
87
|
+
# widthxheight Maximum values of height and width given, aspect ratio preserved.
|
88
|
+
# widthxheight^ Minimum values of width and height given, aspect ratio preserved.
|
89
|
+
# widthxheight! Width and height emphatically given, original aspect ratio ignored.
|
90
|
+
# widthxheight> Change as per widthxheight but only if an image dimension exceeds a specified dimension.
|
91
|
+
# widthxheight< Change dimensions only if both image dimensions exceed specified dimensions.
|
92
|
+
# area@ Resize image to have specified area in pixels. Aspect ratio is preserved.
|
93
|
+
|
94
|
+
THUMBNAIL_NAMINGS = {} # store naming methods eg :iarts => Proc {|aSource,aDestFolder,aBaseUrl,aWidth,aHeight,aOptions| ... } NYI
|
95
|
+
|
96
|
+
# resizing :
|
97
|
+
# to_width,to_height : supply aWidth or aHeight and leave other as nil (width or xheight)
|
98
|
+
# no_change : aWidth and aHeight as nil (original WidthxHeight)
|
99
|
+
# fit : aOptions[:resize_mode] = :fit, maintain aspect, one axis short (default, no modifier)
|
100
|
+
# fit_padded : aOptions[:resize_mode] = :fit_padded, maintain aspect, fill missing area with aOptions[:background_color] (not yet supported)
|
101
|
+
# stretch : aOptions[:resize_mode] = :stretch, (! modifier)
|
102
|
+
# cropfill : aOptions[:resize_mode] = :cropfill (Paperclip adds # modifier)
|
103
|
+
|
104
|
+
# naming options :
|
105
|
+
# supply a block : return a name given the original parameters (possibly slightly modified)
|
106
|
+
# aOptions[:name] is a string : just return this value
|
107
|
+
# aOptions[:name] is a Proc : call this with the original parameters (possibly slightly modified)
|
108
|
+
|
109
|
+
# aOptions :
|
110
|
+
# :resize_mode : see above
|
111
|
+
# :name : see above
|
112
|
+
# :return_details : returns details hash instead of url. :src contains value normally returned
|
113
|
+
# returns the resulting url
|
114
|
+
def render_thumbnail(
|
115
|
+
aSource, # source file
|
116
|
+
aDestFolder, # folder to put new file in
|
117
|
+
aBaseUrl, # equivalent URL for aDestFolder
|
118
|
+
aWidth, # width (nil means auto)
|
119
|
+
aHeight, # height (nil means auto)
|
120
|
+
aOptions = nil
|
121
|
+
)
|
122
|
+
src = ''
|
123
|
+
aOptions ||= {}
|
124
|
+
if aOptions[:return_details]
|
125
|
+
details = {
|
126
|
+
:aSource => aSource,
|
127
|
+
:aDestFolder => aDestFolder,
|
128
|
+
:aBaseUrl => aBaseUrl,
|
129
|
+
:aWidth => aWidth,
|
130
|
+
:aHeight => aHeight,
|
131
|
+
:aOptions => aOptions,
|
132
|
+
}
|
133
|
+
else
|
134
|
+
details = {}
|
135
|
+
end
|
136
|
+
if aSource
|
137
|
+
begin
|
138
|
+
RAILS_DEFAULT_LOGGER.debug 'render_thumbnail: aSource='+aSource
|
139
|
+
aOptions ||= {}
|
140
|
+
aOptions[:resize_mode] ||= :fit
|
141
|
+
|
142
|
+
throw RuntimeError.new("file doesn't exist #{aSource}") unless File.exists? aSource
|
143
|
+
extThumb = 'jpg' #MiscUtils.file_extension(File.basename(aSource),false).downcase
|
144
|
+
throw RuntimeError.new("could not get file geometry #{aSource}") unless geomImage = Paperclip::Geometry.from_file(aSource)
|
145
|
+
|
146
|
+
if aWidth || aHeight
|
147
|
+
w,h = aWidth,aHeight
|
148
|
+
else
|
149
|
+
w,h = geomImage.width,geomImage.height # w,h will never be nil,nil
|
150
|
+
end
|
151
|
+
|
152
|
+
resize_spec = "#{w.to_s}#{h ? 'x'+h.to_s : ''}"
|
153
|
+
resize_mod = '' # aOptions[:resize_mode]==:fit
|
154
|
+
resize_mod = '#' if aOptions[:resize_mode]==:cropfill
|
155
|
+
resize_mod = '!' if aOptions[:resize_mode]==:stretch
|
156
|
+
resize_char = case aOptions[:resize_mode]
|
157
|
+
when :cropfill: 'C'
|
158
|
+
when :stretch: 'S'
|
159
|
+
else 'F'
|
160
|
+
end
|
161
|
+
|
162
|
+
if block_given?
|
163
|
+
nameThumb = yield(aSource,aDestFolder,aBaseUrl,aWidth,aHeight,aOptions)
|
164
|
+
elsif aOptions[:name].is_a?(String)
|
165
|
+
nameThumb = aOptions[:name]
|
166
|
+
elsif aOptions[:name].is_a?(Proc)
|
167
|
+
nameThumb = aOptions[:name].call(aSource,aDestFolder,aBaseUrl,aWidth,aHeight,aOptions)
|
168
|
+
else
|
169
|
+
# default naming
|
170
|
+
nameThumb = MiscUtils.file_no_extension(File.basename(aSource),false)
|
171
|
+
nameThumb = nameThumb.urlize unless aOptions[:urlize]==false
|
172
|
+
nameThumb += '-' unless nameThumb.ends_with?('-')
|
173
|
+
nameThumb += resize_spec+resize_char+'.'+extThumb
|
174
|
+
end
|
175
|
+
pathThumb = File.join(aDestFolder,nameThumb)
|
176
|
+
|
177
|
+
if !File.exists?(pathThumb)
|
178
|
+
throw RuntimeError.new("Failed reading image #{aSource}") unless objThumb = Paperclip::Thumbnail.new(File.new(aSource), :geometry => resize_spec+resize_mod, :format => :jpg)
|
179
|
+
objThumb.basename = MiscUtils.file_no_extension(nameThumb)
|
180
|
+
throw RuntimeError.new("Failed making thumbnail #{aSource}") unless foThumb = objThumb.make
|
181
|
+
FileUtils.cp(foThumb.path,pathThumb)
|
182
|
+
FileUtils.chmod(0644,pathThumb)
|
183
|
+
FileUtils.rm(foThumb.path)
|
184
|
+
end
|
185
|
+
src = File.join(aBaseUrl,nameThumb)
|
186
|
+
details.merge!({
|
187
|
+
:geomImage => geomImage,
|
188
|
+
:w => w,
|
189
|
+
:h => h,
|
190
|
+
:nameThumb => nameThumb,
|
191
|
+
:pathThumb => pathThumb,
|
192
|
+
:objThumb => objThumb
|
193
|
+
}) if aOptions[:return_details]
|
194
|
+
rescue Exception => e
|
195
|
+
RAILS_DEFAULT_LOGGER.warn "thumberize_img error: #{e.inspect}"
|
196
|
+
RAILS_DEFAULT_LOGGER.debug e.backtrace
|
197
|
+
src = ''
|
198
|
+
end
|
199
|
+
end
|
200
|
+
details[:src] = src
|
201
|
+
return aOptions[:return_details] ? details : src
|
202
|
+
end
|
203
|
+
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
1
207
|
module BcmsTools
|
2
208
|
module Thumbnails
|
3
209
|
|
4
210
|
def self.thumbnail_name_from_attachment(aAttachment,aWidth,aHeight)
|
5
|
-
extThumb = aAttachment.file_extension
|
211
|
+
extThumb = 'jpg' #aAttachment.file_extension
|
6
212
|
size = "#{aWidth.to_s}x#{aHeight.to_s}"
|
7
213
|
result = File.basename(aAttachment.file_location)+'-'
|
8
214
|
result += if aWidth && aHeight
|
@@ -89,29 +295,33 @@ module BcmsTools
|
|
89
295
|
urlImage = XmlUtils.quick_att_from_tag(img,'src')
|
90
296
|
|
91
297
|
att = BcmsTools::Thumbnails::attachment_from_url(urlImage)
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
298
|
+
return img = framed_attachment_img(att,aWidth,aHeight,img)
|
299
|
+
|
300
|
+
#src = attachment_max_src(aAttachment,aWidth,aHeight,img)
|
301
|
+
#
|
302
|
+
#pathImage = att && att.full_file_location
|
303
|
+
#
|
304
|
+
#throw RuntimeError.new("file doesn't exist #{pathImage}") unless File.exists? pathImage
|
305
|
+
#throw RuntimeError.new("could not get file geometry #{pathImage}") unless geomImage = Paperclip::Geometry.from_file(pathImage)
|
306
|
+
#
|
307
|
+
#aDestWidth,aDestHeight = BcmsTools::Thumbnails::scale_to_fit(geomImage.width,geomImage.height,aWidth,aHeight).map {|i| i.to_i}
|
308
|
+
#
|
309
|
+
#nameThumb = BcmsTools::Thumbnails::thumbnail_name_from_attachment(att,aWidth,aHeight)
|
310
|
+
#
|
311
|
+
#pathThumb = File.join(APP_CONFIG[:thumbs_cache],nameThumb)
|
312
|
+
#
|
313
|
+
#if !File.exists?(pathThumb)
|
314
|
+
# # generate thumbnail at size to fit container
|
315
|
+
# throw RuntimeError.new("Failed reading image #{pathImage}") unless objThumb = Paperclip::Thumbnail.new(File.new(pathImage), "#{aDestWidth}x#{aDestHeight}")
|
316
|
+
# throw RuntimeError.new("Failed making thumbnail #{pathImage}") unless foThumb = objThumb.make
|
317
|
+
# FileUtils.cp(foThumb.path,pathThumb,:preserve => true)
|
318
|
+
# FileUtils.chmod(0644,pathThumb)
|
319
|
+
# FileUtils.rm(foThumb.path)
|
320
|
+
# #POpen4::shell_out("sudo -u tca chgrp www-data #{pathThumb}; sudo -u tca chmod 644 #{pathThumb}")
|
321
|
+
#end
|
112
322
|
|
113
|
-
img = XmlUtils.quick_set_att(img,'src',File.join(APP_CONFIG[:thumbs_url],nameThumb))
|
114
|
-
return HtmlUtils.fixed_frame_image(img,aWidth,aHeight,aDestWidth,aDestHeight)
|
323
|
+
#img = XmlUtils.quick_set_att(img,'src',src) # File.join(APP_CONFIG[:thumbs_url],nameThumb))
|
324
|
+
#return HtmlUtils.fixed_frame_image(img,aWidth,aHeight,aDestWidth,aDestHeight)
|
115
325
|
rescue Exception => e
|
116
326
|
RAILS_DEFAULT_LOGGER.warn "thumberize_img error: #{e.inspect}"
|
117
327
|
RAILS_DEFAULT_LOGGER.debug e.backtrace
|
@@ -121,123 +331,166 @@ module BcmsTools
|
|
121
331
|
|
122
332
|
def attachment_cropped_src(aAttachment,aWidth,aHeight)
|
123
333
|
return '' if !aAttachment
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
334
|
+
|
335
|
+
Buzzcore::ImageUtils.render_thumbnail(
|
336
|
+
aAttachment.full_file_location,
|
337
|
+
APP_CONFIG[:thumbs_cache],
|
338
|
+
APP_CONFIG[:thumbs_url],
|
339
|
+
aWidth,
|
340
|
+
aHeight,
|
341
|
+
{
|
342
|
+
:name => BcmsTools::Thumbnails::thumbnail_name_from_attachment(aAttachment,aWidth,aHeight),
|
343
|
+
:resize_mode => :cropfill
|
344
|
+
}
|
345
|
+
)
|
346
|
+
|
347
|
+
#begin
|
348
|
+
# pathImage = aAttachment.full_file_location
|
349
|
+
# throw RuntimeError.new("file doesn't exist #{pathImage}") unless File.exists? pathImage
|
350
|
+
# nameThumb = BcmsTools::Thumbnails::thumbnail_name_from_attachment(aAttachment,aWidth,aHeight)
|
351
|
+
# pathThumb = File.join(APP_CONFIG[:thumbs_cache],nameThumb)
|
352
|
+
# if !File.exists?(pathThumb)
|
353
|
+
# # generate thumbnail at size to fit container
|
354
|
+
# throw RuntimeError.new("Failed reading image #{pathImage}") unless objThumb = Paperclip::Thumbnail.new(File.new(pathImage), "#{aWidth}x#{aHeight}#")
|
355
|
+
# throw RuntimeError.new("Failed making thumbnail #{pathImage}") unless foThumb = objThumb.make
|
356
|
+
# FileUtils.cp(foThumb.path,pathThumb)
|
357
|
+
# FileUtils.chmod(0644,pathThumb)
|
358
|
+
# FileUtils.rm(foThumb.path)
|
359
|
+
# end
|
360
|
+
# return File.join(APP_CONFIG[:thumbs_url],nameThumb)
|
361
|
+
#rescue Exception => e
|
362
|
+
# RAILS_DEFAULT_LOGGER.warn "thumberize_img error: #{e.inspect}"
|
363
|
+
# RAILS_DEFAULT_LOGGER.debug e.backtrace
|
364
|
+
# return ''
|
365
|
+
#end
|
143
366
|
end
|
144
367
|
|
145
|
-
def
|
146
|
-
return
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
368
|
+
def shellescape(str)
|
369
|
+
# An empty argument will be skipped, so return empty quotes.
|
370
|
+
return "''" if str.empty?
|
371
|
+
|
372
|
+
str = str.dup
|
373
|
+
|
374
|
+
# Process as a single byte sequence because not all shell
|
375
|
+
# implementations are multibyte aware.
|
376
|
+
str.gsub!(/([^A-Za-z0-9_\-.,:\/@\n])/n, "\\\\\\1")
|
377
|
+
|
378
|
+
# A LF cannot be escaped with a backslash because a backslash + LF
|
379
|
+
# combo is regarded as line continuation and simply ignored.
|
380
|
+
str.gsub!(/\n/, "'\n'")
|
381
|
+
|
382
|
+
return str
|
383
|
+
end
|
384
|
+
|
385
|
+
def shellescape2(aString)
|
386
|
+
result = shellescape(aString)
|
387
|
+
result.gsub!('\\','\\\\\\')
|
388
|
+
end
|
166
389
|
|
167
390
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
391
|
+
def image_max_src(aImagePath,aWidth,aHeight)
|
392
|
+
Buzzcore::ImageUtils.render_thumbnail(
|
393
|
+
aImagePath,
|
394
|
+
APP_CONFIG[:thumbs_cache],
|
395
|
+
APP_CONFIG[:thumbs_url],
|
396
|
+
aWidth,
|
397
|
+
aHeight
|
398
|
+
)
|
399
|
+
end
|
400
|
+
#
|
401
|
+
# aSource, # source file
|
402
|
+
# aDestFolder, # folder to put new file in
|
403
|
+
# aBaseUrl, # equivalent URL for aDestFolder
|
404
|
+
# aWidth, # width (nil means auto)
|
405
|
+
# aHeight, # height (nil means auto)
|
406
|
+
# aOptions = nil
|
407
|
+
#)
|
408
|
+
#
|
409
|
+
#
|
410
|
+
#
|
411
|
+
# return '' if !aImagePath
|
412
|
+
# begin
|
413
|
+
# pathImage = aImagePath
|
414
|
+
# throw RuntimeError.new("file doesn't exist #{pathImage}") unless File.exists? pathImage
|
415
|
+
# throw RuntimeError.new("could not get file geometry #{pathImage}") unless geomImage = Paperclip::Geometry.from_file(shellescape2(pathImage))
|
416
|
+
# #nameThumb = BcmsTools::Thumbnails::thumbnail_name_from_attachment(aAttachment,aWidth,aHeight)
|
417
|
+
# #def self.thumbnail_name_from_attachment(aAttachment,aWidth,aHeight)
|
418
|
+
# extThumb = MiscUtils.file_extension(File.basename(aImagePath)).downcase
|
419
|
+
# size = "#{aWidth.to_s}x#{aHeight.to_s}"
|
420
|
+
# nameThumb = MiscUtils.file_no_extension(File.basename(aImagePath))+'-'
|
421
|
+
# nameThumb += if aWidth || aHeight
|
422
|
+
# size+'.'+extThumb
|
423
|
+
# else
|
424
|
+
# '*'
|
425
|
+
# end
|
426
|
+
# #result
|
427
|
+
# #end
|
428
|
+
#
|
429
|
+
#
|
430
|
+
#
|
431
|
+
#
|
432
|
+
#
|
433
|
+
# pathThumb = File.join(APP_CONFIG[:thumbs_cache],nameThumb)
|
434
|
+
#
|
435
|
+
# aDestWidth,aDestHeight = BcmsTools::Thumbnails::scale_to_fit(geomImage.width,geomImage.height,aWidth,aHeight).map {|i| i.to_i}
|
436
|
+
# if !File.exists?(pathThumb)
|
437
|
+
# # generate thumbnail at size to fit container
|
438
|
+
# throw RuntimeError.new("Failed reading image #{pathImage}") unless objThumb = Paperclip::Thumbnail.new(File.new(shellescape2(pathImage)), "#{aDestWidth}x#{aDestHeight}")
|
439
|
+
# throw RuntimeError.new("Failed making thumbnail #{pathImage}") unless foThumb = objThumb.make
|
440
|
+
# FileUtils.cp(foThumb.path,pathThumb)
|
441
|
+
# FileUtils.chmod(0644,pathThumb)
|
442
|
+
# FileUtils.rm(foThumb.path)
|
443
|
+
# end
|
444
|
+
# return File.join(APP_CONFIG[:thumbs_url],nameThumb)
|
445
|
+
# rescue Exception => e
|
446
|
+
# RAILS_DEFAULT_LOGGER.warn "thumberize_img error: #{e.inspect}"
|
447
|
+
# RAILS_DEFAULT_LOGGER.debug e.backtrace
|
448
|
+
# return ''
|
449
|
+
# end
|
450
|
+
#end
|
186
451
|
|
187
452
|
|
188
453
|
def attachment_max_src(aAttachment,aWidth,aHeight)
|
189
454
|
return '' if !aAttachment
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
throw RuntimeError.new("Failed reading image #{pathImage}") unless objThumb = Paperclip::Thumbnail.new(File.new(pathImage), "#{aDestWidth}x#{aDestHeight}")
|
201
|
-
throw RuntimeError.new("Failed making thumbnail #{pathImage}") unless foThumb = objThumb.make
|
202
|
-
FileUtils.cp(foThumb.path,pathThumb)
|
203
|
-
FileUtils.chmod(0644,pathThumb)
|
204
|
-
FileUtils.rm(foThumb.path)
|
205
|
-
end
|
206
|
-
return File.join(APP_CONFIG[:thumbs_url],nameThumb)
|
207
|
-
rescue Exception => e
|
208
|
-
RAILS_DEFAULT_LOGGER.warn "thumberize_img error: #{e.inspect}"
|
209
|
-
RAILS_DEFAULT_LOGGER.debug e.backtrace
|
210
|
-
return ''
|
211
|
-
end
|
455
|
+
Buzzcore::ImageUtils.render_thumbnail(
|
456
|
+
aAttachment.full_file_location,
|
457
|
+
APP_CONFIG[:thumbs_cache],
|
458
|
+
APP_CONFIG[:thumbs_url],
|
459
|
+
aWidth,
|
460
|
+
aHeight,
|
461
|
+
{
|
462
|
+
:name => BcmsTools::Thumbnails::thumbnail_name_from_attachment(aAttachment,aWidth,aHeight)
|
463
|
+
}
|
464
|
+
)
|
212
465
|
end
|
213
466
|
|
214
467
|
|
215
|
-
def framed_attachment_img(aAttachment,aWidth,aHeight)
|
468
|
+
def framed_attachment_img(aAttachment,aWidth,aHeight,aImg=nil)
|
469
|
+
return '' if !aAttachment
|
216
470
|
begin
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
if !File.exists?(pathThumb)
|
229
|
-
throw RuntimeError.new("Failed reading image #{pathImage}") unless objThumb = Paperclip::Thumbnail.new(File.new(pathImage), "#{aDestWidth}x#{aDestHeight}")
|
230
|
-
throw RuntimeError.new("Failed making thumbnail #{pathImage}") unless foThumb = objThumb.make
|
231
|
-
FileUtils.cp(foThumb.path,pathThumb)
|
232
|
-
FileUtils.chmod(0644,pathThumb)
|
233
|
-
FileUtils.rm(foThumb.path)
|
234
|
-
end
|
471
|
+
details = Buzzcore::ImageUtils.render_thumbnail(
|
472
|
+
aAttachment.full_file_location,
|
473
|
+
APP_CONFIG[:thumbs_cache],
|
474
|
+
APP_CONFIG[:thumbs_url],
|
475
|
+
aWidth,
|
476
|
+
aHeight,
|
477
|
+
{
|
478
|
+
:return_details => true,
|
479
|
+
:name => BcmsTools::Thumbnails::thumbnail_name_from_attachment(aAttachment,aWidth,aHeight)
|
480
|
+
}
|
481
|
+
)
|
235
482
|
|
236
|
-
|
237
|
-
|
483
|
+
if details[:pathThumb]
|
484
|
+
dw,dh = Buzzcore::ImageUtils.image_file_dimensions(details[:pathThumb]) # might be able to optimize using details[:objThumb]
|
485
|
+
else
|
486
|
+
dw,dh = aWidth,aHeight
|
487
|
+
end
|
488
|
+
aImg ||= "<img width=\"#{dw}\" height=\"#{dh}\" />"
|
489
|
+
aImg = XmlUtils.quick_set_att(aImg,'src',details[:src])
|
490
|
+
return HtmlUtils.fixed_frame_image(aImg,aWidth,aHeight,dw,dh)
|
238
491
|
rescue Exception => e
|
239
492
|
RAILS_DEFAULT_LOGGER.warn "thumberize_img error: #{e.inspect}"
|
240
|
-
RAILS_DEFAULT_LOGGER.debug e.backtrace
|
493
|
+
RAILS_DEFAULT_LOGGER.debug e.backtrace
|
241
494
|
return ''
|
242
495
|
end
|
243
496
|
end
|
@@ -89,8 +89,8 @@ Cms::FormBuilder.class_eval do
|
|
89
89
|
result = StringUtils.split3(result,/<div class="fields file_fields.*?>/) {|h,m,t| XmlUtils.quick_join_att(m,'class','thumbnail_upload',' ') }
|
90
90
|
unless aOptions[:remove_check_box]==false || object.new_record?
|
91
91
|
checkbox = '<div style="display: block; float: right; width: auto; height: auto;">'+remove_check_box()+'</div>'
|
92
|
-
result = StringUtils.split3(result
|
93
|
-
m
|
92
|
+
result = StringUtils.split3(result,/<\/div>\Z/){|h,m,t|
|
93
|
+
checkbox+'<br clear="all">'+m
|
94
94
|
}
|
95
95
|
end
|
96
96
|
result = StringUtils.split3(result,/<div.*?>/){|h,m,t| m+'<br clear="all" />'}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bcms_tools
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- buzzware
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-04-
|
12
|
+
date: 2010-04-30 00:00:00 +08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -30,7 +30,7 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 2.1.
|
33
|
+
version: 2.3.1.1
|
34
34
|
version:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: browsercms
|