Created
June 15, 2012 07:03
-
-
Save suapapa/2935113 to your computer and use it in GitHub Desktop.
Convert image file to C byte array
This file contains 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
#!/usr/bin/python | |
import sys | |
import Image | |
fileName = sys.argv[1] | |
img = Image.open(fileName) | |
img = img.convert('L') | |
w, h = img.size | |
data = img.tostring() | |
name = fileName[:fileName.rfind('.')] | |
name = name.replace(' ', '_') | |
line_buffer = [] | |
print 'char %s_%dx%d[] = \\'%(name, w, h) | |
for p in data: | |
line_buffer.append("\\x%02x"%ord(p)) | |
if len(line_buffer) >= 18: | |
print ' "%s"\\'%(''.join(line_buffer)) | |
line_buffer = [] | |
print ";" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment