Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 30th, 2012  |  syntax: Python  |  size: 2.17 KB  |  hits: 43  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/env python
  2. # ImageMagick must be installed to use this script.
  3.  
  4. convert_exe = r'd:\wheelgen\im\convert.exe'
  5. stroke_color = 'blue'
  6. fill_color = 'yellow'
  7. wheel_font = 'Amstrad-CPC-Extended-Tweak-Regular' # use convert -list font to get proper names
  8. img_size = '300x140'
  9. stroke_width = '1'
  10.  
  11. import sys, os, re, string
  12.  
  13. if len(sys.argv) != 3:
  14.     print ("usage: %s <hsdb.xml> <output batch file>" % sys.argv[0])
  15.     exit(1)
  16.  
  17. if not os.path.exists(sys.argv[1]):
  18.     print ("error: %s does not exist" % sys.argv[1])
  19.     exit(1)
  20.  
  21. game_xml = open(sys.argv[1])
  22. game_count = 0
  23. gamedb = []
  24.  
  25. while 1:
  26.     line = game_xml.readline()
  27.     if not line: break
  28.  
  29.     name_match = re.match( r'.*<game name="([^"]*)', line )
  30.     if name_match:
  31.         game_name = name_match.group(1)
  32.         next_line = game_xml.readline()
  33.         desc_match = re.match( r'.*<description>([^<^(]*)', next_line )
  34.  
  35.         if desc_match:
  36.             game_desc = desc_match.group(1)
  37.  
  38.             game_name = game_name.strip()
  39.             game_name = string.replace(game_name,'&apos;','\'')
  40.             game_name = string.replace(game_name,'&amp;','&')
  41.  
  42.             game_desc = game_desc.strip()
  43.             game_desc = string.replace(game_desc,'&apos;','\'')
  44.             game_desc = string.replace(game_desc,'&amp;','&')
  45.  
  46.             gamedb.append((game_name,game_desc))
  47.             game_count += 1
  48.  
  49. game_xml.close()
  50.  
  51. batch = open(os.path.abspath(sys.argv[2]),'w')
  52.  
  53. for game_name, game_desc in gamedb:
  54.     cmd = convert_exe +' -background transparent ^\n \
  55.         -fill ' + fill_color + '^\n \
  56.         -stroke ' + stroke_color + '^\n \
  57.         -strokewidth ' + stroke_width + ' ^\n \
  58.         -size ' + img_size + ' ^\n \
  59.         -font ' + wheel_font + ' ^\n \
  60.         -gravity center ^\n \
  61.         caption:"' + game_desc + '" ^\n \
  62.         -trim ^\n \
  63.         ( +clone -background black -shadow 100x3 ) ^\n \
  64.         +swap ^\n \
  65.         +repage ^\n \
  66.         -geometry -4-4 ^\n \
  67.         -composite ^\n \
  68.         "' + game_name + '.png"\n\n'
  69.  
  70.     batch.write(cmd)
  71.  
  72. print sys.argv[2] + ' written - ' + str(game_count) + ' entries.'
  73. batch.flush()
  74. batch.close()