Class: Blobsterix::Transformations::Impl::Image2HTML

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

Instance Method Summary collapse

Methods inherited from Transformation

#name, #to_s

Methods included from Logable

#logger, #logger=

Instance Method Details

#input_typeObject



162
163
164
# File 'lib/blobsterix/transformation/image_transformation.rb', line 162

def input_type()
  @input_type ||= Blobsterix::AcceptType.new "image/*"
end

#is_format?Boolean

Returns:

  • (Boolean)


170
171
172
# File 'lib/blobsterix/transformation/image_transformation.rb', line 170

def is_format?()
  true
end

#output_typeObject



166
167
168
# File 'lib/blobsterix/transformation/image_transformation.rb', line 166

def output_type()
  @output_type ||= Blobsterix::AcceptType.new "text/html"
end

#transform(input_path, target_path, value) ⇒ Object



174
175
176
177
178
179
180
181
182
183
184
# File 'lib/blobsterix/transformation/image_transformation.rb', line 174

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("<html><body>Mimetype: #{type}<br>Width: #{image[:width]}<br>Height: #{image[:height]}</body></html>")
  }
end