Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(48)

Unified Diff: client/testing/dartest/resources/img2base64.py

Issue 8905021: Dartest CL - Please review (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: client/testing/dartest/resources/img2base64.py
===================================================================
--- client/testing/dartest/resources/img2base64.py (revision 0)
+++ client/testing/dartest/resources/img2base64.py (revision 0)
@@ -0,0 +1,19 @@
+#!/usr/bin/python
pdr 2011/12/14 21:02:36 There's a small effort to rewrite these types of s
shauvik 2011/12/16 07:19:27 Okay - that would be the next exercise after I get
+"""
+Converts an image into its Base-64 data string
+Useful for embedding images in HTML or CSS without having a separate file
+"""
+
+import sys,base64
+
+if __name__ == "__main__":
+ if(len(sys.argv) < 2):
+ print "Usage: img2base64.py <image>"
+ exit(1)
+ try:
+ fName = sys.argv[1]
+ data = base64.encodestring(open(fName,"rb").read()).replace('\n', '')
+ fType = fName[-3:] #Use last 3 chars as file type
+ print "data:image/%s;base64,%s"%(fType,data)
+ except IOError as e:
+ print "Failed to open file:", sys.argv[1]
Property changes on: client/testing/dartest/resources/img2base64.py
___________________________________________________________________
Added: svn:executable
+ *

Powered by Google App Engine
This is Rietveld 408576698