bin/httpthumbnailer in httpthumbnailer-0.0.2 vs bin/httpthumbnailer in httpthumbnailer-0.0.3

- old
+ new

@@ -22,10 +22,20 @@ unless @thumbnailer @thumbnailer = Thumbnailer.new(:logger => logger) @thumbnailer.method('crop') do |image, spec| image.resize_to_fill(spec.width, spec.height) end + + @thumbnailer.method('fit') do |image, spec| + image.resize_to_fit(spec.width, spec.height) + end + + @thumbnailer.method('pad') do |image, spec| + Magick::Image.new(spec.width, spec.height) { + self.background_color = Magick::Pixel.new(Magick::MaxRGB, Magick::MaxRGB, Magick::MaxRGB, Magick::MaxRGB) # transparent + }.composite!(image.resize_to_fit(spec.width, spec.height), Magick::CenterGravity, Magick::OverCompositeOp) + end end end sinatra.helpers do def plain_exception(exception) @@ -49,20 +59,20 @@ thumbnail_specs = ThumbnailSpecs.from_uri(specs) status 200 headers "Content-Type" => "multipart/mixed; boundary=\"#{settings.boundary}\"" stream do |out| - thumbnail_specs.each do |ts| - logger.info "Thumbnailing: #{ts}" + thumbnail_specs.each do |spec| + logger.info "Thumbnailing: #{spec}" out << "--#{settings.boundary}\r\n" begin - thumbnail = @thumbnailer.thumbnail('current', ts) + thumbnail = @thumbnailer.thumbnail('current', spec) thumbnail_data = thumbnail.to_blob do |inf| - inf.format = ts.format + inf.format = spec.format end - out << "Content-Type: #{ts.mime}\r\n\r\n" + out << "Content-Type: #{spec.mime}\r\n\r\n" out << thumbnail_data thumbnail_data = nil thumbnail.destroy! rescue => e