Class: Thumbnail
- Inherits:
-
Object
- Object
- Thumbnail
- Defined in:
- lib/thumbnail.rb
Instance Method Summary collapse
- #add_overlay ⇒ Object
- #images ⇒ Object
-
#initialize(id, tmpfile) ⇒ Thumbnail
constructor
A new instance of Thumbnail.
- #uri_path ⇒ Object
- #write(suffix = nil) ⇒ Object
Constructor Details
#initialize(id, tmpfile) ⇒ Thumbnail
Returns a new instance of Thumbnail.
4 5 6 7 8 9 |
# File 'lib/thumbnail.rb', line 4 def initialize id, tmpfile @id = id @images = Magick::ImageList.new(tmpfile.path) @filename_parts = [@id] end |
Instance Method Details
#add_overlay ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/thumbnail.rb', line 34 def @filename_parts << "overlay" filename = File.join(Dir.pwd, "assets","overlay.png") # Fallback to asset packaged with gem filename = GEMDIR.join("assets", "overlay.png") unless File.exists? filename @images << Magick::ImageList.new(filename)[0] self end |
#images ⇒ Object
11 12 13 |
# File 'lib/thumbnail.rb', line 11 def images @images end |
#uri_path ⇒ Object
15 16 17 |
# File 'lib/thumbnail.rb', line 15 def uri_path File.join("/", "thumbs", container_dir, filename) end |
#write(suffix = nil) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/thumbnail.rb', line 19 def write suffix = nil final = @images.shift @images.each do |image| final = final.composite(image, Magick::CenterGravity, Magick::OverCompositeOp) end extra_parts = [suffix] unless suffix.nil? final.write(root.join(container_dir, filename)) #it should be easier and cleaner with flatten: however: no idea how to CenterGravity that # see http://stackoverflow.com/questions/15724387/how-to-flatten-rmagick-images-and-center-them #@images.flatten_images.write(File.join("public", "thumbs", parts.join("_") + ".png")) self end |