Help to fix error "unbalanced parenthesis"

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
excel
Posts: 18
Joined: 2015-12-19T13:16:12-07:00
Authentication code: 1151

Help to fix error "unbalanced parenthesis"

Post by excel »

image.png
Image

How in one exec command to compose a frame and to get result.png?

result.png
Image

Code: Select all

convert -size 200x50 xc:none -stroke '#ffffb7' -strokewidth 1 -fill none \
-draw "stroke-dasharray 4 4 path 'M 8,8 192,8 192,42 8,42 8,8' " \
+write mpr:dotted_frame \
\( image.png mpr:dotted_frame -gravity center -composite -alpha Set -depth 8 +write result.png \)
this code returns error:
convert: unbalanced parenthesis `)' @ error/convert.c/ConvertImageCommand/3236.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Help to fix error "unbalanced parenthesis"

Post by snibgo »

You can't end a convert command with a close parenthesis. The last thing must be an image name, without a preceeding "write". This could be "NULL:", so adding that to the end would cure that syntax error.

At your open-parens, you already have one image in the list, the dotted frame, so that could be deleted before the "(".

But you are writing the frame to mpr, then reading it. I can't see why. Nor do I see why you have parentheses at all. This seems more reasonable:

Code: Select all

convert -size 200x50 xc:none -stroke '#ffffb7' -strokewidth 1 -fill none \
-draw "stroke-dasharray 4 4 path 'M 8,8 192,8 192,42 8,42 8,8' " \
image.png +swap -gravity center -composite -alpha Set -depth 8 result.png
snibgo's IM pages: im.snibgo.com
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: Help to fix error "unbalanced parenthesis"

Post by GeeMack »

excel wrote:How in one exec command to compose a frame and to get result.png?
It might be easier to understand what your code is doing if you bring the "image.png" in first. Then after it's in the working stack, build your dotted line rectangle inside the parentheses. At that point you have two images in the stack, the orange rectangle is the first image and the dotted rectangle is the second. Then after you set the gravity to center, "-composite" will simply lay your dotted lines down onto your orange rectangle and output "result.png".

Maybe try something like this...

Code: Select all

convert image.png \
   \( -size 200x50 xc:none -stroke '#ffffb7' -strokewidth 1 -fill none \
   -draw "stroke-dasharray 4 4 path 'M 8,8 192,8 192,42 8,42 8,8' " \) \
   -gravity center -composite -alpha Set -depth 8 result.png
You don't really need to write anything to a memory register "mpr:dotted_frame" unless you'll be doing something else with that by adding more to your command. And you don't need the "+write" before your output file name. IM already assumes the last image file name in the command will be the output file.

You can even make the orange rectangle then draw the dotted lines directly on it without any compositing if a short command like this would serve your purpose...

Code: Select all

convert -size 200x50 xc:'#e84700' -stroke '#ffffb7' -strokewidth 1 -fill none \
   -draw "stroke-dasharray 4 4 path 'M 8,8 192,8 192,42 8,42 8,8'" -depth 8 result2.png
excel
Posts: 18
Joined: 2015-12-19T13:16:12-07:00
Authentication code: 1151

Re: Help to fix error "unbalanced parenthesis"

Post by excel »

Dear friends, thank you very much!

I used it (GeeMack's code):
GeeMack wrote:

Code: Select all

convert image.png \
   \( -size 200x50 xc:none -stroke '#ffffb7' -strokewidth 1 -fill none \
   -draw "stroke-dasharray 4 4 path 'M 8,8 192,8 192,42 8,42 8,8' " \) \
   -gravity center -composite -alpha Set -depth 8 result.png
Post Reply