0

OS Ubuntu 12.04 precise, python 2.7.3, pyramid web framework, IM 6.4.7-1

I've got Python code (inside a Pyramid Web Framework application, but that should be irrelevant) which takes a captured image capture.jpg and then needs to do two ImageMagick processes on the image. The first is convert to label the image (works), the second is composite to apply a watermark over the image and label (doesn't work). At first I thought the second operation silently failed due to the image not being ready, but adding a wait timer indicates that's not so. Any idea of how to combine both operations? They can't be combined into one shell command.

    now = datetime.datetime.utcnow()
    inpfile = "/home/brian/capture.jpg"
    tfile = "/home/brian/watermark.png"
    label = ("SN7 %s" % now.strftime("%Y%m%d%H%M%S")) 
    outfile = ("/home/brian/%s" % now.strftime("CAM_%Y%m%d%H%M%S") + ".jpg")
    args = []
    args += ["-background", "White"]
args += ["-pointsize","42"]
    args += ["label: "+ label]
    args += ["-gravity", "Center"]
args += ["-append"]
subprocess.check_call(["convert",inpfile] + args + [outfile])
time.sleep(5)
imp = []
imp += ["-dissolve", "25"]
imp += ["-gravity", "South"]
subprocess.check_call(["composite"] + [imp] + tfile + outfile + outfile)
    return [] 
  • Why can't they be combined in one call? Are the parameters dynamically updated depending on the first result? Also, can we assume your process works fine on the commandline? Lastly, what is the error code from the second subprocess? If there is none, then `composite` does its job, just not the way you expect it. –  Mar 06 '13 at 11:14

1 Answers1

0

I think you are mixing the listsina wrong way. imp is already a list and you placed it in [] in the check_call call. So you get a list in a list. Additionaly tfile is a string which can not be concatenated to a list, but this should be visible as a TypeError Exception. And a third problem i found; you concatenate outfile as string to outfile, so there will be no valid input and output file for the second process.

krase
  • 1,006
  • 7
  • 18
  • Thank you @krase. Yes, the process worked fine on the commandline. and they cannot be combined in one call. Turns out that the solution was to use subprocess.call instead of subprocess.check_call for a reason I don't yet fully understand. The working code: inpfile = args = [] args += ["-background", "White"] ... args += ["-append"] subprocess.call(["convert",inpfile] + args + [outfile]) imp = [] imp += ["-dissolve", "25"] imp += ["-gravity", "South"] subprocess.call(["composite"] + imp + [tfile] + [outfile] + [outfile]) – user2139543 Mar 16 '13 at 06:18