Module: Kontrast::ThumbnailCreator

Defined in:
lib/kontrast/thumbnail_creator.rb

Class Method Summary collapse

Class Method Details

.create_thumbnails(test, image_names) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/kontrast/thumbnail_creator.rb', line 6

def create_thumbnails(test, image_names)
  # Crop images
  Workers.map(image_names) do |image_name|
    src_path = File.join(Kontrast.path, test.to_s, image_name)

    # Resize to at least 200 width, the crop the top part of the image at 200x200
    # '+repage' means "don't keep the part of the image not shown in the crop"
    # http://www.imagemagick.org/discourse-server/viewtopic.php?t=18545
    options = '-resize "200x200^" -gravity North -crop 200x200+0+0 +repage'
    `convert "#{src_path}" #{options} "#{thumb_path(test, image_name)}"`
  end
end

.thumb_path(test, image_name) ⇒ Object



19
20
21
22
# File 'lib/kontrast/thumbnail_creator.rb', line 19

def thumb_path(test, image_name)
    filename = "#{File.basename(image_name, ".*")}_thumb.png"
    File.join(Kontrast.path, test.to_s, filename)
end