Class: Magick::Image

Inherits:
Object
  • Object
show all
Includes:
Plugin::Thumbnailer::ImageProcessing
Defined in:
lib/httpthumbnailer/plugin/thumbnailer.rb

Instance Method Summary collapse

Methods included from Plugin::Thumbnailer::ImageProcessing

#replace, #use

Instance Method Details

#downscale(f) ⇒ Object



429
430
431
# File 'lib/httpthumbnailer/plugin/thumbnailer.rb', line 429

def downscale(f)
	sample(columns / f, rows / f)
end

#find_downscale_factor(max_width, max_height, factor = 1) ⇒ Object



433
434
435
436
437
438
439
440
# File 'lib/httpthumbnailer/plugin/thumbnailer.rb', line 433

def find_downscale_factor(max_width, max_height, factor = 1)
	new_factor = factor * 2
	if columns / new_factor > max_width * 2 and rows / new_factor > max_height * 2
		find_downscale_factor(max_width, max_height, factor * 2)
	else
		factor
	end
end

#render_on_background(background_color, width = nil, height = nil) ⇒ Object



403
404
405
406
407
408
409
410
411
412
413
414
# File 'lib/httpthumbnailer/plugin/thumbnailer.rb', line 403

def render_on_background(background_color, width = nil, height = nil)
	Magick::Image.new(width || self.columns, height || self.rows) {
		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

#resize_to_fill(ncols, nrows = nil, gravity = Magick::CenterGravity) ⇒ Object

non coping version



417
418
419
420
421
422
423
424
425
426
427
# File 'lib/httpthumbnailer/plugin/thumbnailer.rb', line 417

def resize_to_fill(ncols, nrows = nil, gravity = Magick::CenterGravity)
	nrows ||= ncols
	if ncols != columns or nrows != rows
		scale = [ncols / columns.to_f, nrows / rows.to_f].max
		resize(scale * columns + 0.5, scale * rows + 0.5).replace do |image|
			image.crop(gravity, ncols, nrows, true) if ncols != columns or nrows != rows
		end
	else
		crop(gravity, ncols, nrows, true) if ncols != columns or nrows != rows
	end
end