Created
February 7, 2015 06:03
-
-
Save borodean/8ff85cbe1959a069ecbc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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