Skip to content

Instantly share code, notes, and snippets.

@1wheel
Last active March 27, 2019 03:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1wheel/bcaa860506520cefb711aa4a9f885c12 to your computer and use it in GitHub Desktop.
Save 1wheel/bcaa860506520cefb711aa4a9f885c12 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
from PIL import Image
import math
from os import listdir
imgSize = 8192
# imgSize = 512*2
svgPath = '/Users/adampearce/Desktop/1wheel/datavizsociety/badges/svg/'
pngPath = '/Users/adampearce/Desktop/1wheel/datavizsociety/badges/png/'
svg_images = listdir(svgPath)
svg_images.sort()
# svg_images = svg_images[:32]
test_images = []
for i, img in enumerate(svg_images):
test_images.append(img.replace('svg', 'png'))
print(test_images[0])
# test_image_list = '/Users/adampearce/Desktop/1wheel/datavizsociety/badges/png' # path to the image list
# with open(test_image_list, 'r') as f:
# test_images = f.readlines()
# test_images = map(str.strip, test_images)
grid = int(math.sqrt(len(test_images))) + 1
image_height = int(imgSize / grid)
image_width = int(imgSize / grid)
print(image_width)
print(image_height)
big_image = Image.new(
mode='RGBA',
size=(image_width * grid, image_height * grid),
color=(0,0,0,0)) # fully transparent
for i in range(len(test_images)):
row = int(i / grid)
col = i % grid
img = Image.open(pngPath + test_images[i])
img = img.resize((image_height, image_width), Image.ANTIALIAS)
row_loc = row * image_height
col_loc = col * image_width
big_image.paste(img, (col_loc, row_loc)) # NOTE: the order is reverse due to PIL saving
big_image.save('../load-projector-data/sprite_image.png')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment