Class: Plugin::Thumbnailer::InputImage
- Inherits:
-
Object
- Object
- Plugin::Thumbnailer::InputImage
- Extended by:
- Forwardable
- Includes:
- ClassLogging, MetaData
- Defined in:
- lib/httpthumbnailer/plugin/thumbnailer.rb
Instance Method Summary collapse
-
#equal?(image) ⇒ Boolean
needs to be seen as @image when returned in replace block.
- #height ⇒ Object
-
#initialize(image, processing_methods, options = {}) ⇒ InputImage
constructor
A new instance of InputImage.
- #process_image(method, width, height, options) ⇒ Object
- #thumbnail(spec) ⇒ Object
-
#use ⇒ Object
behave as @image in processing.
-
#width ⇒ Object
We use base values since it might have been loaded with size hint and prescaled.
Methods included from MetaData
Constructor Details
#initialize(image, processing_methods, options = {}) ⇒ InputImage
Returns a new instance of InputImage.
90 91 92 93 |
# File 'lib/httpthumbnailer/plugin/thumbnailer.rb', line 90 def initialize(image, processing_methods, = {}) @image = image @processing_methods = processing_methods end |
Instance Method Details
#equal?(image) ⇒ Boolean
needs to be seen as @image when returned in replace block
151 152 153 |
# File 'lib/httpthumbnailer/plugin/thumbnailer.rb', line 151 def equal?(image) super image or @image.equal? image end |
#height ⇒ Object
146 147 148 |
# File 'lib/httpthumbnailer/plugin/thumbnailer.rb', line 146 def height @image.base_rows end |
#process_image(method, width, height, options) ⇒ Object
123 124 125 126 127 128 |
# File 'lib/httpthumbnailer/plugin/thumbnailer.rb', line 123 def process_image(method, width, height, ) @image.replace do |image| impl = @processing_methods[method] or raise UnsupportedMethodError, method impl.call(image, width, height, ) end end |
#thumbnail(spec) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/httpthumbnailer/plugin/thumbnailer.rb', line 95 def thumbnail(spec) spec = spec.dup # default backgraud is white spec.['background-color'] = spec..fetch('background-color', 'white').sub(/^0x/, '#') width = spec.width == :input ? @image.columns : spec.width height = spec.height == :input ? @image.rows : spec.height raise ZeroSizedImageError.new(width, height) if width == 0 or height == 0 begin process_image(spec.method, width, height, spec.).replace do |image| if image.alpha? log.info 'thumbnail has alpha, rendering on background' image.render_on_background(spec.['background-color']) end end.use do |image| Service.stats.incr_total_thumbnails_created image_format = spec.format == :input ? @image.format : spec.format yield Thumbnail.new(image, image_format, spec.) end rescue Magick::ImageMagickError => error raise ImageTooLargeError, error. if error. =~ /cache resources exhausted/ raise end end |
#use ⇒ Object
behave as @image in processing
131 132 133 134 135 |
# File 'lib/httpthumbnailer/plugin/thumbnailer.rb', line 131 def use @image.use do |image| yield self end end |
#width ⇒ Object
We use base values since it might have been loaded with size hint and prescaled
142 143 144 |
# File 'lib/httpthumbnailer/plugin/thumbnailer.rb', line 142 def width @image.base_columns end |