Possible bug -draw polygon IM 6.9.2.8 Q16 Mac OSX Snow Leopard

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Possible bug -draw polygon IM 6.9.2.8 Q16 Mac OSX Snow Leopard

Post by fmw42 »

Input:
Image

I am trying to make the bottom of the image transparent along a sine curve from one side to the other. I compute a sine curve with -function sinusoid and write to txt. Then I get the y coordinates and recompute to floating point accuracy so that it will be anti-aliased along the sine curve. I then get the two bottom corners and add those to the list of coordinates and then draw a mask image for the alpha channel as black at the bottom on a white background. Afterwards there is one non-transparent pixel on the left side in the transparent region at 0,149 which should have been transparent. Note: you need to expand the mask to see the one white dot on the left side in the black region.

Code: Select all

infile="lena.jpg"
amplitude=10
row=128
ww=`convert -ping "$infile" -format "%w" info:`
hh=`convert -ping "$infile" -format "%h" info:`
wm1=$((ww-1))
hm1=$((hh-1))
qrange=`convert xc: -format "%[fx:quantumrange]" info:`
amp=`convert xc: -format "%[fx:$amplitude/$qrange]" info:`
off=`convert xc: -format "%[fx:$row/$qrange]" info:`
coords=`convert -size 1x256 gradient: -rotate 90 -function sinusoid "1,180,0.5,0.5" txt:- |\
sed -n 's/^\([^,]*\),.*: [(]\([^,]*\).*$/\1,\2/p'`
xArr=(`echo "$coords" | cut -d, -f1`)
yArr=(`echo "$coords" | cut -d, -f2`)
len=${#xArr[*]}
#echo "len=$len;"
#echo "${xArr[*]}
#echo "${yArr[*]}
for ((i=0; i<len; i++)); do
yy=`echo "scale=6; $amplitude*${yArr[$i]}*2/$qrange+$row" | bc`
coordArr[$i]="${xArr[$i]},$yy"
done
coords="${coordArr[*]} $wm1,$hm1 0,$hm1"
convert "$infile" \
\( +clone -fill white -colorize 100 -fill black -draw "polygon $coords" -alpha off -write tmp2.png \) \
-compose copy_opacity -composite lena_sine_crop2.png
Image
Image

I even tried closing the polygon by adding the first sine wave point (rounded to 0,138) and added -stroke black -strokewidth 2, but neither of these changes made a difference and did not get rid of the bad point at 0,149.



However, if I draw the mask the opposite polarity (white at the top on black background), it works fine.

Code: Select all

infile="lena.jpg"
amplitude=10
row=128
ww=`convert -ping "$infile" -format "%w" info:`
hh=`convert -ping "$infile" -format "%h" info:`
wm1=$((ww-1))
hm1=$((hh-1))
qrange=`convert xc: -format "%[fx:quantumrange]" info:`
amp=`convert xc: -format "%[fx:$amplitude/$qrange]" info:`
off=`convert xc: -format "%[fx:$row/$qrange]" info:`
coords=`convert -size 1x256 gradient: -rotate 90 -function sinusoid "1,180,0.5,0.5" txt:- |\
sed -n 's/^\([^,]*\),.*: [(]\([^,]*\).*$/\1,\2/p'`
xArr=(`echo "$coords" | cut -d, -f1`)
yArr=(`echo "$coords" | cut -d, -f2`)
len=${#xArr[*]}
#echo "len=$len;"
#echo "${xArr[*]}
#echo "${yArr[*]}
for ((i=0; i<len; i++)); do
yy=`echo "scale=6; $amplitude*${yArr[$i]}*2/$qrange+$row" | bc`
coordArr[$i]="${xArr[$i]},$yy"
done
coords="$wm1,0 0,0 ${coordArr[*]}"
convert "$infile" \
\( +clone -fill black -colorize 100 -fill white -draw "polygon $coords" -alpha off -write tmp3.png \) \
-compose copy_opacity -composite lena_sine_crop3.png

Image
Image
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Possible bug -draw polygon IM 6.9.2.8 Q16 Mac OSX Snow Leopard

Post by magick »

Modify your coords variable as follows:

coords="$wm1,$hm1 0,$hm1 ${coordArr[*]}"

We did not investigate why this works or why the other form fails.
Post Reply