Invalid parameter - Please help - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Invalid parameter - Please help (/thread-15940.html) |
Invalid parameter - Please help - maligmus - Feb-07-2019 I am attempting to create cards for CAH. This code should work, but it receives an error Here is a link to all the files I am using This code is for Python 2 (does not work with Python 3 and I am not sure how to convert it.), I am using v2.7.6 and i receive the following error: Quote:c:\Users\curti\Desktop\CAH\Make Cards>makecards.py white CAHTest.txt Here is the code: import os import sys FRONTS = {'white': 'white front.png', 'black': 'black front.png'} MARGIN = 111 # px, safe-bleed + actual margin (300dpi) TEXT_WIDTH = 600 # px, 300dpi (card width - 2 * MARGIN) FONT = 'HelveticaNeue-Bold' SIZE = 72 def CardAgainstHumanity(text, background_color, back, out): """Writes text onto back, result is in out. color is the background color.""" text_color = 'white' if background_color == 'black' else 'black' text = text.replace('"', '\\"') command = ('convert -font %s -pointsize %d -size %dx ' '-background %s -transparent %s -fill %s "caption:%s" temp.png' % ( FONT, SIZE, TEXT_WIDTH, background_color, background_color, text_color, text.strip())) os.system(command) command = 'composite -geometry +%d+%d "%s" "%s" "%s"' % ( MARGIN, MARGIN, 'temp.png', back, out) os.system(command) def main(): usage = 'Usage: %s <black|white> input.txt' % sys.argv[0] if len(sys.argv) != 3: print >> sys.stderr, usage return if sys.argv[1] not in ('white', 'black'): print >> sys.stderr, usage return background = sys.argv[1] + ' front.png' try: outdir = os.path.splitext(os.path.basename(sys.argv[2]))[0] outdir = os.path.splitext(outdir)[0] os.mkdir(outdir) except OSError: pass print with file(sys.argv[2]) as f: for card_num, line in enumerate(f): outfile = '%s%03d.png' % (sys.argv[1], card_num) outfile = os.path.join(outdir, outfile) text = line.strip() print '\rCreating %s...' % outfile, sys.stdout.flush() CardAgainstHumanity(text, sys.argv[1], background, outfile) print '\rCreated %d cards!%s' % (card_num+1, ' '*30) if __name__ == '__main__': main() RE: Invalid parameter - Please help - buran - Feb-07-2019 It doesn't mention it, but actually I think it needs third party software to be installed - ImageMagick Also, the script is pretty old and uses CLI offered by the program, while there are python bindings that provide pythonic interface. |