Sha256: 7bf91c16d7b663de1335700334f35a6dd4bce516f69f342f7f0fd7a85c108411

Contents?: true

Size: 1008 Bytes

Versions: 11

Compression:

Stored size: 1008 Bytes

Contents

module Sprite
  class ImageWriter
    def initialize(config)
      @config = config
    end
    
    def write(image, name, format, quality = nil, background_color = nil)
      # set up path
      path = image_output_path(name, format)
      FileUtils.mkdir_p(File.dirname(path))
      
      # write sprite image file to disk
      image.write(path) {
        self.quality = quality unless quality.nil?
        self.background_color = background_color unless background_color.nil?
      }
    end
    
    # get the disk path for a location within the image output folder
    def image_output_path(name, format, relative = false)
      path_parts = []
      path_parts << Config.chop_trailing_slash(@config['image_output_path']) if Config.path_present?(@config['image_output_path'])

      cache_buster = "-#{@config['cache_buster']}" if @config['cache_buster']
      path_parts << "#{name}#{cache_buster}.#{format}"
      Config.new(@config).public_path(File.join(*path_parts), relative)
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
amikula-sprite-0.1.13 lib/sprite/image_writer.rb
sprite-0.2.6 lib/sprite/image_writer.rb
amikula-sprite-0.1.12 lib/sprite/image_writer.rb
sprite-0.2.5 lib/sprite/image_writer.rb
sprite-0.2.4 lib/sprite/image_writer.rb
sprite-0.2.2 lib/sprite/image_writer.rb
sprite-0.2.1 lib/sprite/image_writer.rb
sprite-0.2.0 lib/sprite/image_writer.rb
amikula-sprite-0.1.11 lib/sprite/image_writer.rb
amikula-sprite-0.1.10 lib/sprite/image_writer.rb
amikula-sprite-0.1.9 lib/sprite/image_writer.rb