Permalink
Browse files

image data uri generation

  • Loading branch information...
1 parent e1f367b commit 7964501f648fcf4bafc23ce5ad822a654a190499 @lachie lachie committed Aug 14, 2010
Showing with 36 additions and 0 deletions.
  1. +14 −0 lib/whereuat/assets/context.rb
  2. +22 −0 lib/whereuat/assets/image.rb
@@ -0,0 +1,14 @@
+module Whereuat
+ module Assets
+ class Context
+ def bg_url
+ Image.new(images_root+'uat-bg.png')
+ end
+
+ def images_root
+ @images_root ||= Whereuat.dev_root+'images'
+ end
+ end
+ end
+end
+
@@ -0,0 +1,22 @@
+module Whereuat
+ module Assets
+ class Image
+ def initialize(path)
+ @path = Pathname(path)
+ end
+
+ def to_s
+ "data:#{content_type};base64," + ([@path.read].pack("m").gsub("\n",''))
+ end
+
+ def content_type
+ case @path.to_s[/\.([^\.]+)$/,1]
+ when 'png'
+ 'image/png'
+ when 'gif'
+ 'image/gif'
+ end
+ end
+ end
+ end
+end

0 comments on commit 7964501

Please sign in to comment.