Python Forum
Invalid parameter - Please help
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()
Reply
#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.
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [ERROR] ParamValidationError: Parameter validation failed: Invalid type for parameter gdbengo 3 10,976 Dec-26-2022, 08:48 AM
Last Post: ibreeden
  zlib decompress error: invalid code lengths set / invalid block type DreamingInsanity 0 6,828 Mar-29-2020, 12:44 PM
Last Post: DreamingInsanity
  TreeTagger : parameter file invalid : english.par Raph0909 0 2,799 Apr-12-2019, 12:12 PM
Last Post: Raph0909

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020