Calling convert from Python script

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
mfkfx
Posts: 1
Joined: 2017-08-14T05:18:03-07:00
Authentication code: 1151

Calling convert from Python script

Post by mfkfx » 2017-08-14T05:53:53-07:00

Hello,

I think I have a problem with escape sequences when calling "convert" from Python using os.system('convert...').
I want to draw a text in an Image like this:
"Temperature: 28.1 °C"

What is working:

Code: Select all

-draw \"text 40,240 Humidity_'+format(round(humidity,1))+'\"
which results in "Humidity_39.6"

What is not working:

Code: Select all

-draw \"text 40,240 Humidity:'+format(round(humidity,1))+'\"
which results simply in "Humidity" with error message "convert: non-conforming drawing primitive definition `:' @ error/draw.c/DrawImage/3184."

Same thing here:

Code: Select all

-draw \"text 40,240 Humidity\ '+format(round(humidity,1))+'\"
which results in "Humidity\ 39.6". So the space is displayed correctly, but the line continuation character is drawn as well


Can you help me? It would be great to have a tab between the fixed text and the value. For example:

Code: Select all

Temperature:	17.3 °C
Humidity:	48.2 %rH
Thank you very much in advance!

Regards

snibgo
Posts: 9379
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Calling convert from Python script

Post by snibgo » 2017-08-14T06:11:18-07:00

When a string contains a space, it must be quoted, or the parser won't know where it ends. The same is true of the colon character, and probably others.
snibgo's IM pages: im.snibgo.com

Post Reply