lib/httpthumbnailer/plugin/thumbnailer.rb in httpthumbnailer-1.1.1 vs lib/httpthumbnailer/plugin/thumbnailer.rb in httpthumbnailer-1.1.2
- old
+ new
@@ -48,10 +48,16 @@
def initialize(width, height)
super("at least one image dimension is zero: #{width}x#{height}")
end
end
+ class InvalidColorNameError < ArgumentError
+ def initialize(color)
+ super("invalid color name: #{color}")
+ end
+ end
+
module ImageProcessing
def replace
@use_count ||= 0
processed = nil
begin
@@ -185,17 +191,17 @@
class Service
include ClassLogging
extend Stats
def_stats(
- :total_images_loaded,
- :total_images_reloaded,
- :total_images_downscaled,
- :total_thumbnails_created,
- :images_loaded,
- :max_images_loaded,
- :max_images_loaded_worker,
+ :total_images_loaded,
+ :total_images_reloaded,
+ :total_images_downscaled,
+ :total_thumbnails_created,
+ :images_loaded,
+ :max_images_loaded,
+ :max_images_loaded_worker,
:total_images_created,
:total_images_destroyed,
:total_images_created_from_blob,
:total_images_created_initialize,
:total_images_created_resize,
@@ -394,10 +400,14 @@
class Magick::Image
include Plugin::Thumbnailer::ImageProcessing
def render_on_background(background_color, width = nil, height = nil)
Magick::Image.new(width || self.columns, height || self.rows) {
- self.background_color = background_color
+ begin
+ self.background_color = background_color
+ rescue ArgumentError
+ raise Plugin::Thumbnailer::InvalidColorNameError.new(background_color)
+ end
self.depth = 8
}.replace do |background|
background.composite!(self, Magick::CenterGravity, Magick::OverCompositeOp)
end
end