class Wraith::Thumbnails

Attributes

wraith[R]

Public Class Methods

new(config) click to toggle source
# File lib/wraith/thumbnails.rb, line 9
def initialize(config)
  @wraith = Wraith::Wraith.new(config)
end

Public Instance Methods

generate_thumbnails() click to toggle source
# File lib/wraith/thumbnails.rb, line 13
def generate_thumbnails
  files = Dir.glob("#{wraith.directory}/*/*.png")

  Parallel.each(files, :in_processes => Parallel.processor_count) do |filename|
    new_name = filename.gsub(/^#{wraith.directory}/, "#{wraith.directory}/thumbnails")
    thumbnail_image(filename, new_name)
  end
end
thumbnail_image(png_path, output_path) click to toggle source
# File lib/wraith/thumbnails.rb, line 22
def thumbnail_image(png_path, output_path)
  unless File.directory?(File.dirname(output_path))
    FileUtils.mkdir_p(File.dirname(output_path))
  end

  `convert #{png_path.shellescape} -thumbnail 200 -crop #{wraith.thumb_width.to_s}x#{wraith.thumb_height.to_s}+0+0 #{output_path.shellescape}`
end