Skip to content

Instantly share code, notes, and snippets.

@borodean
Created February 7, 2015 06:03
Show Gist options
  • Select an option

  • Save borodean/8ff85cbe1959a069ecbc to your computer and use it in GitHub Desktop.

Select an option

Save borodean/8ff85cbe1959a069ecbc to your computer and use it in GitHub Desktop.
require 'chunky_png'
module SassExtensions::Functions
def inline_stroke(color, spacing = Sass::Script::Number.new(0))
assert_type color, :Color
assert_type spacing, :Number
stroke_spacing = spacing.value.round
stroke_width = [1, stroke_spacing].max
stroke_color = ChunkyPNG::Color.rgba(*color.rgb, (255 * color.alpha).round)
png = ChunkyPNG::Image.new(stroke_width + stroke_spacing, 1)
stroke_width.times do |x|
png[x, 0] = stroke_color
end
base64 = ['data:image/png;base64,', png.to_blob(:fast_rgba)].pack('A*m').gsub(/\n/, '')
Sass::Script::String.new("url(#{ base64 })")
end
Sass::Script::Functions.declare :inline_stroke, [:color, :spacing]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment