Class: Sequel::Plugins::Paperclip::Processors::Image
- Inherits:
-
Object
- Object
- Sequel::Plugins::Paperclip::Processors::Image
- Defined in:
- lib/sequel_paperclip/processors/image.rb,
lib/sequel_paperclip/processors/image.rb
Defined Under Namespace
Classes: Geometry
Instance Attribute Summary collapse
-
#attachment ⇒ Object
readonly
Returns the value of attribute attachment.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(attachment, options) ⇒ Image
constructor
A new instance of Image.
- #post_runs ⇒ Object
- #pre_runs(model, src_path) ⇒ Object
- #run(style, style_options, dst_file) ⇒ Object
Constructor Details
#initialize(attachment, options) ⇒ Image
Returns a new instance of Image.
10 11 12 13 14 |
# File 'lib/sequel_paperclip/processors/image.rb', line 10 def initialize(, ) @name = "image" @attachment = @options = end |
Instance Attribute Details
#attachment ⇒ Object (readonly)
Returns the value of attribute attachment.
7 8 9 |
# File 'lib/sequel_paperclip/processors/image.rb', line 7 def @attachment end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/sequel_paperclip/processors/image.rb', line 6 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/sequel_paperclip/processors/image.rb', line 8 def @options end |
Instance Method Details
#post_runs ⇒ Object
56 57 |
# File 'lib/sequel_paperclip/processors/image.rb', line 56 def post_runs end |
#pre_runs(model, src_path) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/sequel_paperclip/processors/image.rb', line 16 def pre_runs(model, src_path) @model = model @src_path = src_path @src_geometry = Geometry.from_file(@src_path) raise ArgumentError, "failed to identify #{@src_path}" unless @src_geometry end |
#run(style, style_options, dst_file) ⇒ Object
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 |
# File 'lib/sequel_paperclip/processors/image.rb', line 23 def run(style, , dst_file) dst_geometry = Geometry.from_s([:geometry]) dst_crop = [:geometry][-1,1] == "#" resize_str, crop_str = @src_geometry.transform(dst_geometry, dst_crop) cmd = [] cmd << "convert" cmd << "-resize" cmd << "'#{resize_str}'" if crop_str cmd << "-crop" cmd << "'#{crop_str}'" end if [:convert_arguments] cmd << [:convert_arguments] end case [:format] when :gif, :apng cmd << "'#{@src_path}'" else # extract first frame only (works even when input is non-animated) cmd << "'#{@src_path}[0]'" end cmd << "'#{[:format]}:#{dst_file.path}'" `#{cmd*" "}` end |