Draw polyline problem

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
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Draw polyline problem

Post by Bonzo »

I am drawing a line graph and currently have to use -flip as it is drawn upside down; any idea whats going on ?

Code: Select all

convert -size 800x500 xc:none -fill none -stroke Red -strokewidth 1 -gravity southwest -draw "polyline 100,260 150,290 200,380 250,310 300,400 350,210 " test.png
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Draw polyline problem

Post by fmw42 »

Y image coordinates are at the top of the image and increase downward. The X,Y origin is at the top left.

You can flip the resulting image or you can recompute your Y coordinates as Height-Y-1.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Draw polyline problem

Post by Bonzo »

So using -gravity southwest has no effect in this case ?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Draw polyline problem

Post by fmw42 »

Bonzo wrote:So using -gravity southwest has no effect in this case ?
Not that I know! But I will defer to the IM developers for a definitive answer.

I believe that only -draw "text... and -draw "image over... are gravity sensitive. see http://www.imagemagick.org/Usage/draw/#primitives
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Draw polyline problem

Post by Bonzo »

Thanks Fred I have modified my code so that the lines are drawn then the image is flipped before adding the text.

THE DATA FOR THE LINES IS MADE UP NOT ACTUAL !
Image

At a guess it takes 2 seconds to create the image above on my PC. I have removed all the tempory images but one but it had little effect.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Draw polyline problem

Post by fmw42 »

I look forward to seeing your real comparison results graphed.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Draw polyline problem

Post by Bonzo »

I have hit a bit of a hurdle at the moment on how to scale and annotate the vertical axis; I will also need to tidy up the code. This was basicaly an exercise to try writing a php class to create a line graph.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Draw polyline problem

Post by fmw42 »

Have you considered using Gnuplot. see http://www.gnuplot.info/
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Draw polyline problem

Post by Bonzo »

I looked at gnuplot once before but it is more complicated than I need; also as I say once I get it working how I want I am going to try to convert it to a php class just to try try out writing a class.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Draw polyline problem

Post by anthony »

Bonzo wrote:So using -gravity southwest has no effect in this case ?
Gravity positioning only effects text and images, and in these cases also effects justification around the position point.

Gravity is not actually part of SVG standard and as such typically used for drawing.

This is noted at the end of the IM examples, Drawing, Primitives, text and image
http://www.imagemagick.org/Usage/draw/#primitive_text
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Draw polyline problem

Post by anthony »

Bonzo wrote:I looked at gnuplot once before but it is more complicated than I need; also as I say once I get it working how I want I am going to try to convert it to a php class just to try try out writing a class.
As a user (and old programmer) of gnuplot, it isn't really very complicated. Just get a small example and follow it.
The real problem is that it does not have a very good help mechanism, and usage examples is more of a 'find what you like and study it'

The best idea with gnuplot is keep it simple as long as you can.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply