Skip to content

Commit

Permalink
image data uri generation
Browse files Browse the repository at this point in the history
  • Loading branch information
lachie committed Aug 14, 2010
1 parent e1f367b commit 7964501
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/whereuat/assets/context.rb
Original file line number Diff line number Diff line change
@@ -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

22 changes: 22 additions & 0 deletions lib/whereuat/assets/image.rb
Original file line number Diff line number Diff line change
@@ -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.