draw dashed lines in imagemagick

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?".
Locked
manit
Posts: 157
Joined: 2009-01-30T22:31:26-07:00

draw dashed lines in imagemagick

Post by manit »

hi,
I am using

Code: Select all

$ convert --version
Version: ImageMagick 6.8.9-9 Q16 x86_64 2019-11-12 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
$ uname -a
Linux lxuser-ThinkPad-E470 4.15.0-88-generic #88~16.04.1-Ubuntu SMP Wed Feb 12 04:19:15 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
$ lsb_release  -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 16.04.5 LTS
Release:	16.04
Codename:	xenial
I am trying to draw a dashed line but the finishing is not proper.
My commands are as follows

Code: Select all

convert -size 100x100 xc:none  blank.png
convert blank.png -fill red -stroke black -strokewidth 10 -draw "circle 50,50 50,90" circle.png
convert circle.png -stroke white -strokewidth 5 -fill none  -draw "stroke-dasharray 10 10  path 'M 50,10 L 50,90'" circle-with-seam.png
circle-with-seam.png is present at https://ibb.co/cKqZ7Lt

Note the last dash at the bottom is thin while others are thick.

What I am doing wrong here ?

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

Re: draw dashed lines in imagemagick

Post by snibgo »

I get a similar bad result with v6.9.9-50, but no problem with v7.0.8-64.

If I make the line length one pixel longer or shorter, v6.9.9-50 gives a good result.
snibgo's IM pages: im.snibgo.com

User avatar
fmw42
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: draw dashed lines in imagemagick

Post by fmw42 »

Looks fine on IM 6.9.10.95 and 7.0.9.25 Q16 Mac OSX. I see the four top wide white lines and no thin 5th one at the bottom.

Note that Linux distributions often only update for security. So they may not have patched for that fix. Or the fix may have been after your version was patched.

manit
Posts: 157
Joined: 2009-01-30T22:31:26-07:00

Re: draw dashed lines in imagemagick

Post by manit »

ok , I will try with imagemagick on windows .

manit
Posts: 157
Joined: 2009-01-30T22:31:26-07:00

Re: draw dashed lines in imagemagick

Post by manit »

I used
Version: ImageMagick 7.0.7-25 Q16 x86 2018-03-04 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Visual C++: 180040629
Features: Cipher DPC HDRI
Delegates (built-in): bzlib cairo flif freetype gslib heic jng jp2 jpeg lcms lqr openexr pangocairo png ps raw rsvg tiff webp xml zlib
On
64 bit windows 10 pro .
This time I got https://ibb.co/hF4Vvnq

Notice that there 4 dashes are alright but fifth is thin /

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

Re: draw dashed lines in imagemagick

Post by snibgo »

It works for Fred and me, with later v7 versions than you have. I suggest you try the current v7 version.
snibgo's IM pages: im.snibgo.com

manit
Posts: 157
Joined: 2009-01-30T22:31:26-07:00

Re: draw dashed lines in imagemagick

Post by manit »

ImageMagick-7.0.9-26-portable-Q16-x64 gave right results on windows.

manit
Posts: 157
Joined: 2009-01-30T22:31:26-07:00

Re: draw dashed lines in imagemagick

Post by manit »

I plan to convert this image to svg .
Is that equivalent to drawing circle using svg ?
Or
Drawing circle and dotted line via svg command will give sharper images ?

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

Re: draw dashed lines in imagemagick

Post by snibgo »

SVG is a vector format. It won't give sharper images than IM. But you can rasterize SVG images at any size you want, with equal sharpness.
snibgo's IM pages: im.snibgo.com

manit
Posts: 157
Joined: 2009-01-30T22:31:26-07:00

Re: draw dashed lines in imagemagick

Post by manit »

when I converted png to svg then svg had content
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="100px" height="100px" viewBox="0 0 100 100" enable-background="new 0 0 100 100" xml:space="preserve"> <image id="image0" width="100" height="100" x="0" y="0"
href="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAMAAABHPGVmAAAABGdBTUEAALGPC/xhBQAAACBjSFJN
AAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAABGlBMVEUAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD///9AQEAiAAB8AAC4AAD5AAD/
AAD/QED6AABhAADDAAAjAAC0AAD4AAA2AADNAAAGAACMAAD8AAD9AADUAABPAAD0AAD+AACRAABQ
AAD3AAB9AADcAADxAADdAADOAAA3AADEAAAHAACQAAD2AABiAADnAAD4wbDzAAAANnRSTlMAATVc
This shows that there is no geometrical formula saved in svg.
If this SVG is used to make higher resolution PNG then the image will not be sharper.
Is that correct ?

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

Re: draw dashed lines in imagemagick

Post by snibgo »

Yes, that's correct, because IM has made a raster image and embedded that in the SVG. If you want to render the SVG at different sizes, you need to write the appropriate SVG.
snibgo's IM pages: im.snibgo.com

Locked