Class: Abrizer::Sprites

Inherits:
Object
  • Object
show all
Defined in:
lib/abrizer/sprites.rb

Instance Method Summary collapse

Constructor Details

#initialize(filename, output_dir = nil) ⇒ Sprites

Returns a new instance of Sprites.



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/abrizer/sprites.rb', line 4

def initialize(filename, output_dir=nil)
  @filename = filename
  @output_directory = File.join output_dir, 'sprites'
  # TODO: make video sprites options configurable
  @options = {
    seconds: 10,
    width: 160,
    columns: 4,
    group: 20,
    gif: false,
    keep_images: true
  }
end

Instance Method Details

#createObject



18
19
20
21
22
23
# File 'lib/abrizer/sprites.rb', line 18

def create
  processor = VideoSprites::Processor.new(@filename, @output_directory, @options)
  processor.process
  FileUtils.chmod_R "go+r", @output_directory
  optimize_images
end

#individual_image_globObject



50
51
52
# File 'lib/abrizer/sprites.rb', line 50

def individual_image_glob
  File.join @output_directory, "images/*.jpg"
end

#individual_image_pathsObject



46
47
48
# File 'lib/abrizer/sprites.rb', line 46

def individual_image_paths
  Dir.glob(individual_image_glob)
end

#optimize_imagesObject



25
26
27
28
# File 'lib/abrizer/sprites.rb', line 25

def optimize_images
  optimize_sprites
  optimize_individual_images
end

#optimize_individual_imagesObject



42
43
44
# File 'lib/abrizer/sprites.rb', line 42

def optimize_individual_images
  `jpegoptim #{individual_image_paths.join(' ')}`
end

#optimize_spritesObject



30
31
32
# File 'lib/abrizer/sprites.rb', line 30

def optimize_sprites
  `jpegoptim #{sprite_paths.join(' ')}`
end

#sprite_pathsObject



34
35
36
# File 'lib/abrizer/sprites.rb', line 34

def sprite_paths
  Dir.glob(sprites_glob)
end

#sprites_globObject



38
39
40
# File 'lib/abrizer/sprites.rb', line 38

def sprites_glob
  File.join @output_directory, "*.jpg"
end