Class: Blobsterix::Transformations::Impl::Image2Json

Inherits:
Transformation show all
Defined in:
lib/blobsterix/transformation/image_transformation.rb,
lib/blobsterix/transformation/image_transformation.rb

Instance Method Summary collapse

Methods inherited from Transformation

#to_s

Methods included from Logable

#logger, #logger=

Instance Method Details

#input_typeObject



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

Returns:

  • (Boolean)


200
201
202
# File 'lib/blobsterix/transformation/image_transformation.rb', line 200

def is_format?()
  true
end

#nameObject



188
189
190
# File 'lib/blobsterix/transformation/image_transformation.rb', line 188

def name()
  "json"
end

#output_typeObject



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