Sha256: 6a950716771adc37f1e307780cbf33abd58359501fbf899d56ed2f5d8668a0ad

Contents?: true

Size: 994 Bytes

Versions: 2

Compression:

Stored size: 994 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

2 entries across 2 versions & 1 rubygems

Version Path
sprite-0.3.0 lib/sprite/image_writer.rb
sprite-0.2.7 lib/sprite/image_writer.rb