Skip to content

Instantly share code, notes, and snippets.

@kswedberg
Created April 17, 2012 03:10
Show Gist options
  • Save kswedberg/2403117 to your computer and use it in GitHub Desktop.
Save kswedberg/2403117 to your computer and use it in GitHub Desktop.

Revisions

  1. kswedberg created this gist Apr 17, 2012.
    48 changes: 48 additions & 0 deletions snippet.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,48 @@
    # General
    output_style = :expanded
    relative_assets = true
    line_comments = false

    project_path = File.dirname(__FILE__) + "/"
    utils_dir = project_path + "utils/"

    # Sass Paths
    http_path = "/"
    http_javascripts_path = http_path + "assets/js/"
    http_stylesheets_path = http_path + "assets/css/"
    http_images_path = http_stylesheets_path + "img/"
    http_fonts_path = http_stylesheets_path + "fonts/"

    # Sass Directories (relative to this config.rb file)
    javascripts_dir = "../assets/js/"
    css_dir = "../assets/css/"
    sass_dir = css_dir + "src/"
    images_dir = css_dir + "img/"

    # Quantize 8-bit sprites
    on_sprite_saved do |file|
    if !is_32bit?(file) && ENV["QUANTIZE_IMG"] == "y"
    quantize(file, utils_dir + "pngquant/pngquant-mac")
    end
    if ENV["OPTIMIZE_IMG"] == "y"
    optimize(file, utils_dir + "pngout/pngout-mac")
    end
    end

    # Methods
    def is_32bit?(file)
    File.basename(file).match(/^png(24|32)/)
    end

    def quantize(file, binary)
    png8_file = file.sub(/\.png/, "-fs8.png")
    system binary + " " + file
    sleep 2
    system "mv -f " + png8_file + " " + file
    growl("Sprite: " + File.basename(file) + " quantized")
    end

    def optimize(file, binary)
    system binary + " " + file + " -y"
    growl("Sprite: " + File.basename(file) + " optimized")
    end