Skip to content

Instantly share code, notes, and snippets.

@zeffii
Created May 20, 2015 21:32
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 zeffii/020a79b0362ffe9f77f0 to your computer and use it in GitHub Desktop.
Save zeffii/020a79b0362ffe9f77f0 to your computer and use it in GitHub Desktop.
avoid the bash file generation, send line by line to subprocess.Popen()
import os
import subprocess
def generate(from_file, x, y, filenames, type='.png'):
filenames = filenames.split()
with open('local01.tff', 'w') as m:
print('generated local file')
yield "convert {0} local01.miff".format(from_file)
for i, filename in enumerate(filenames):
l = "convert local01.miff -crop {0}x{1}+{2}+0 {3}{4}"
yield l.format(x, y, i * x, filename, type)
yield "rm local01.miff"
def main():
rendered_name = 'RENDERED_ARRAY.png'
icons = "VTX V2X XALL BIX PERP CCEN EXM"
file_strings = generate(rendered_name, 32, 32, icons)
for line in file_strings:
subprocess.Popen(line.split())
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment