Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Invalid parameter - Please help
#1
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

Creating CAHTest\white000.png...Invalid Parameter - Helvetica-Neue-Bold
'composite' is not recognized as an internal or external command,
operable program or batch file.
Creating CAHTest\white001.png...Invalid Parameter - Helvetica-Neue-Bold
'composite' is not recognized as an internal or external command,
operable program or batch file.
Creating CAHTest\white002.png...Invalid Parameter - Helvetica-Neue-Bold
'composite' is not recognized as an internal or external command,
operable program or batch file.
Creating CAHTest\white003.png...Invalid Parameter - Helvetica-Neue-Bold
'composite' is not recognized as an internal or external command,
operable program or batch file.
Creating CAHTest\white004.png...Invalid Parameter - Helvetica-Neue-Bold
'composite' is not recognized as an internal or external command,
operable program or batch file.
Creating CAHTest\white005.png...Invalid Parameter - Helvetica-Neue-Bold
'composite' is not recognized as an internal or external command,
operable program or batch file.
Creating CAHTest\white006.png...Invalid Parameter - Helvetica-Neue-Bold
'composite' is not recognized as an internal or external command,
operable program or batch file.
Creating CAHTest\white007.png...Invalid Parameter - Helvetica-Neue-Bold
'composite' is not recognized as an internal or external command,
operable program or batch file.
Created 8 cards!

c:\Users\curti\Desktop\CAH\Make Cards>

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()
Quote
#2
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.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  SyntaxError: invalid syntax jurg1505 5 122 Jul-14-2019, 03:30 PM
Last Post: ichabod801
  Invalid archive error when attempting to install dash bootstrap components meaydemi 0 117 Jul-11-2019, 05:49 PM
Last Post: meaydemi
  Why are my parameter names greyed out? 357mag 1 224 Jul-06-2019, 07:49 PM
Last Post: ichabod801
  SyntaxError: invalid syntax Truman 7 3,681 Jun-16-2019, 04:54 PM
Last Post: apollo
  ValueError: invalid rectstyle object fen1c5 1 275 Jun-05-2019, 02:51 PM
Last Post: heiner55
  Why do i have invalid syntax on a line after print, i see no error ? iofhua 5 229 May-24-2019, 05:42 PM
Last Post: Yoriz
  sqlite3 question - execute method with :parameter richalt2 2 157 May-20-2019, 05:35 PM
Last Post: woooee
  Python bytecode: 64 bit parameter to LOAD_CONST physics 0 104 May-12-2019, 04:59 PM
Last Post: physics
  Can't work out parameter format for LibVLC functions Domarius 10 416 Apr-30-2019, 10:54 PM
Last Post: Domarius
  invalid syantx metro779966 3 291 Apr-26-2019, 03:00 PM
Last Post: keames

Forum Jump:


Users browsing this thread: 1 Guest(s)