Page 1 of 1

convert command gives error in bash script

Posted: 2018-05-01T04:46:07-07:00
by manit
I am using

$ convert --version
Version: ImageMagick 6.8.9-9 Q16 x86_64 2017-07-31 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules OpenMP
Delegates: bzlib cairo djvu fftw fontconfig freetype jbig jng jpeg lcms lqr ltdl lzma openexr pangocairo png rsvg tiff wmf x xml zlib
in 64 bit ubuntu OS.

Here is my script
[script]
#!/bin/bash
img_file=$2
while read one_line; do
let "first_num = $(echo $one_line|cut -d ' ' -f1)"
let "second_num = $(echo $one_line|cut -d ' ' -f2)"
echo first num-$first_num
echo second num-$second_num
let "periphery = $((second_num+5))"
echo periphery-$periphery
convert /home/lxuser/Downloads/xyt/$img_file -fill none -strokewidth 1 -draw \'"circle $first_num,$second_num $first_num,$periphery"\' \'"/home/lxuser/Downloads/xyt/$img_file"\'
echo convert /home/lxuser/Downloads/xyt/$img_file -fill none -strokewidth 1 -draw \'"circle $first_num,$second_num $first_num,$periphery"\' \'"/home/lxuser/Downloads/xyt/$img_file"\'
done < $1
[/script]

I pass it two files
(1)sth.xyt which is of the form
13 146 202 6
23 251 22 15
26 51 180 17
30 224 34 15
33 263 202 34
35 455 225 7
46 176 202 67
58 109 191 33
61 151 202 33
63 47 180 35
(2)<image_file>

The script takes first two numbers and draws circle of radius 5 on the image_file passed as second argument .
Strangely, I get error (in red)
first num-13
second num-146
periphery-151
convert: non-conforming drawing primitive definition `circle 13,146 13,151' @ error/draw.c/DrawImage/3184.
convert /home/lxuser/Downloads/xyt/don.jpg -fill none -strokewidth 1 -draw 'circle 13,146 13,151' '/home/lxuser/Downloads/xyt/don.jpg'

If I simply copy paste the echoed command . it works.

Re: convert command gives error in bash script

Posted: 2018-05-01T05:02:05-07:00
by snibgo
Your script has the -draw argument in both double-quotes and single-quotes. Why? This will cause problems because bash will remove only the outer quotes.

Re: convert command gives error in bash script

Posted: 2018-05-02T01:42:48-07:00
by manit
i had to use double quotes because I am using $first_num .
I will put just that variable in double quotes and see what happens.

Re: convert command gives error in bash script

Posted: 2018-05-02T05:16:14-07:00
by manit
Now my script is

#!/bin/bash
img_file=$2
while read one_line; do
let "first_num = $(echo $one_line|cut -d ' ' -f1)"
let "second_num = $(echo $one_line|cut -d ' ' -f2)"
echo first num-$first_num
echo second num-$second_num
let "periphery = $((second_num+5))"
echo periphery-$periphery
convert /home/lxuser/Downloads/"$img_file" -fill none -strokewidth 1 -draw \'circle "$first_num","$second_num" "$first_num","$periphery"\' /home/lxuser/Downloads/"$img_file"
echo convert /home/lxuser/Downloads/"$img_file" -fill none -strokewidth 1 -draw \'circle "$first_num","$second_num" "$first_num","$periphery"\' /home/lxuser/Downloads/"$img_file"
done < $1


I get
first num-13
second num-146
periphery-151
convert: non-conforming drawing primitive definition `circle' @ error/draw.c/DrawImage/3184.
convert: unable to open image `13,146': No such file or directory @ error/blob.c/OpenBlob/2712.
convert: unable to open image `13,146': No such file or directory @ error/blob.c/OpenBlob/2712.
convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
convert: unable to open image `13,151'': No such file or directory @ error/blob.c/OpenBlob/2712.
convert: unable to open image `13,151'': No such file or directory @ error/blob.c/OpenBlob/2712.
convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
convert: non-conforming drawing primitive definition `circle' @ error/draw.c/DrawImage/3184.
convert /home/lxuser/Downloads/sth.png -fill none -strokewidth 1 -draw 'circle 13,146 13,151' /home/lxuser/Downloads/sth.png

Re: convert command gives error in bash script

Posted: 2018-05-02T05:54:06-07:00
by snibgo
All those quotes confuse me. Perhaps they also confuse bash and IM. This works for me, using Cygwin bash:

Code: Select all

 convert "$img_file" -fill None -strokewidth 1 -draw "circle $first_num,$second_num,$first_num,$periphery" "$img_file"

Re: convert command gives error in bash script

Posted: 2018-05-07T12:54:35-07:00
by manit
sorry for late reply.
Thanks a lot, snibgo.

It works.
Here is the working code
#!/bin/bash
img_file=$2
while read one_line; do
let "first_num = $(echo $one_line|cut -d ' ' -f1)"
let "second_num = $(echo $one_line|cut -d ' ' -f2)"
echo first num-$first_num
echo second num-$second_num
let "periphery = $((second_num+5))"
echo periphery-$periphery
echo convert "$img_file" -fill none -strokewidth 1 -stroke red -draw "circle $first_num,$second_num $first_num,$periphery" "$img_file"
convert "$img_file" -fill none -strokewidth 1 -stroke red -draw "circle $first_num,$second_num $first_num,$periphery" "$img_file"
done < $1