Class: Blobsterix::Transformations::Impl::Image2Json
- Inherits:
-
Transformation
- Object
- Transformation
- Blobsterix::Transformations::Impl::Image2Json
- Defined in:
- lib/blobsterix/transformation/image_transformation.rb,
lib/blobsterix/transformation/image_transformation.rb
Instance Method Summary collapse
- #input_type ⇒ Object
- #is_format? ⇒ Boolean
- #name ⇒ Object
- #output_type ⇒ Object
- #transform(input_path, target_path, value) ⇒ Object
Methods inherited from Transformation
Methods included from Logable
Instance Method Details
#input_type ⇒ Object
192 193 194 |
# File 'lib/blobsterix/transformation/image_transformation.rb', line 192 def input_type() @input_type ||= Blobsterix::AcceptType.new "image/*" end |
#is_format? ⇒ Boolean
200 201 202 |
# File 'lib/blobsterix/transformation/image_transformation.rb', line 200 def is_format?() true end |
#name ⇒ Object
188 189 190 |
# File 'lib/blobsterix/transformation/image_transformation.rb', line 188 def name() "json" end |
#output_type ⇒ Object
196 197 198 |
# File 'lib/blobsterix/transformation/image_transformation.rb', line 196 def output_type() @output_type ||= Blobsterix::AcceptType.new "text/json" end |
#transform(input_path, target_path, value) ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/blobsterix/transformation/image_transformation.rb', line 204 def transform(input_path, target_path, value) type = "image/*" File.open(input_path) {|file| type = MimeMagic.by_magic(file).type } image = type === "image/webp" ? {:width => "unknown", :height => "unknown"} : MiniMagick::Image.open(input_path) File.open(target_path, "w") {|file| file.write({:width => image[:width], :height => image[:height]}.merge(Blobsterix::Storage::FileSystemMetaData.new(input_path).as_json).to_json) } end |