ImageMagick icon indicating copy to clipboard operation
ImageMagick copied to clipboard

Docs and Magick Vector Graphics

Open AlexSunnyMan opened this issue 2 years ago • 4 comments

ImageMagick version

7.1.1-11

Operating system

Linux

Operating system, version and so on

Arch

Description

Greetings!

  1. In docs about whole magick command line options missed -script flag: https://imagemagick.org/script/command-line-options.php.

However, in other image Magick docs appears magick-script, magick -script. Did not find any docs about -script flag, but about script available in other docs:

From https://imagemagick.org/script/magick-script.php: -------------- begin cite ------------------------ Here is an example script:

#!/bin/env magick-script -size 100x100 xc:red ( rose: -rotate -90 ) +append -write show:

Or use the magick utility with the scripting option like this:

#!/bin/magick -script -size 100x100 xc:red ( rose: -rotate -90 ) +append -write show:

You can find additional examples of using magick-script in Examples of ImageMagick Usage.

-------------- end of cite ------------------

  1. Insufficient descriptions in Magick Vector Graphics page: https://imagemagick.org/script/magick-vector-graphics.php

As I see, making miff's, png's, jpeg's from native SVG not support disabling antialias feature. But magick MVG support it. So, conversion between msvg:file.svg to mvg:file.mvg works good.

I try to make my own MVG-picture and try to use patterns. As I think, patterns is like a functions in coding. It very useful. Here my mvg picture:

---- begin ---- push graphic-context viewbox 0 0 100 100 push defs push pattern "test" radial 10,10 20,20 push graphic-context fill red rectangle 5,5 15,15 pop graphic-context push graphic-context fill green rectangle 10,10 20,20 pop graphic-context pop pattern pop defs push graphic-context use url(#test) pop graphic-context pop graphic-context

---- end -----

I give example from https://imagemagick.org/script/magick-vector-graphics.php. A little bit change it and exec: magick mvg:picture.mvg miff:- | display -

Magick says me: ---- begin ----- magick mvg:picture.mvg miff:- | display - magick: non-conforming drawing primitive definition radial' @ error/draw.c/RenderMVGContent/3500. display: no decode delegate for this image format ' @ error/constitute.c/ReadImage/746. display: no decode delegate for this image format `' @ error/constitute.c/ReadImage/746. ----- end ------

Okay, lets delete radial word, magick says: ---- begib ------ magick mvg:picture.mvg miff:- | display - magick: non-conforming drawing primitive definition 10' @ error/draw.c/RenderMVGContent/4506. display: no decode delegate for this image format ' @ error/constitute.c/ReadImage/746. display: no decode delegate for this image format `' @ error/constitute.c/ReadImage/746. ----- end ------

Okay, lets see the docs https://imagemagick.org/script/magick-vector-graphics.php: Syntax of pattern is: push pattern id radial x,y width,height So, what is "radial"? I try to find through Ctrl-F radial word, related flags like gradient operators, magick -list radial. Nothing. Why non-conforming drawing primitive?

Another moments: As I see, words (operators, setting and so on) in MVG picture file are case sensitive: viewbox 0 0 100 100 and viewBox 0 0 100 100 are different operators. Did not find about it in docs

In docs syntax of viewbox is: viewbox x,y x1,y1 - pairs of coma separated values but viewbox x y x1 y1 works too. Nothing about it in docs did not find.

Missing "encoding" setting in Drawings primitive table https://imagemagick.org/script/magick-vector-graphics.php. Operators like clip-path url(name), clip-rule rule, kerning, offset, translate, pops, pushs, use - without description. Perhaps description available in other docs. Good idea that on these descriptions be an link.

In Drawings primitive table in https://imagemagick.org/script/magick-vector-graphics.php

Why push, pop, graphics-context and so on? I think, that MVG file syntax and processing are similar with PostScript/GhostScript. Push and pop is like push and pop to/from stack in ghostscript. What is graphics-context? As I think is some current graphics parameters and states. Push reserves it into stack, pop returns. None about it in docs I find. I think, that single -draw operator is a single push graphics-context - pop graphics-context construction. If need execute drawing from isolated contexts one big -draw instruction need to be splitted to two or more -draw subinstructions or operations executed in different -draw flags.

And now i see two forms: magick-script and magick vector graphics.

  1. When in examples used built-in images like rose, wizard, logo image name is rose:, logo:, wizard:. But actually may be magick:rose, magick:wizard, magick:logo. Same situation with canvas: xc:skyblue instead of canvas:skyblue.

  2. Conversion from SVG to MVG. Example from https://imagemagick.org/script/magick-vector-graphics.php: magick mvg:piechart.svg piechart.jpg not works. But magick MSVG:piechart.svg piechart.jpg works well. As I see normal conversion from native SVG to native MVG only available in this form: magick msvg:native.svg mvg:native.mvg and not in these forms: magick svg:native.svg mvg:native.mvg magick native.svg mvg:native.mvg magick svg:native.svg native.mvg magick native.svg native.mvg In those forms magick converts, but out file contains not MVG native language, just magickly modified initial SVG. Another moment. Usage MVG-picture with format prefix (mvg:pict.mvg) and without it makes different results and magick tool reaction.

  3. Broken link https://imagemagick.org/Usage/file/#x From page https://imagemagick.org/Usage/basics/ Link name X:

  4. Bad thing, that when using: magick x:'root' miff:- | display - grabbed window overlaps window on higher level. Command above executes in terminal window. And so that the open terminal does not overlap the window being shot, it should automatically hide. But this does not happen and a black square is superimposed on the full screen of screen.

Steps to Reproduce

See in description

Images

See in description

AlexSunnyMan avatar Aug 21 '23 14:08 AlexSunnyMan

  1. Yes, https://imagemagick.org/script/command-line-options.php is missing an entry for -script. I suggest:
-script filename

Transfer control to the named file, which can be "-" for stdin.
  1. The page https://imagemagick.org/script/magick-vector-graphics.php says the syntax for "push pattern" is:

push pattern id radial x,y width,height

I think that is wrong, and "radial" should be removed. See the examples at the top of that page.

The SVG document https://www.w3.org/TR/SVG/pservers.html#PatternElement has an example SVG that uses a pattern, with url. I name this file pattern.svg:

<?xml version="1.0" standalone="no"?>
<svg xmlns="http://www.w3.org/2000/svg"
     version="1.1"
     viewBox="0 0 300 200" >

  <title>Example pattern01</title>
  <desc>Fill an ellipse using a pattern paint server.</desc>

  <defs>
    <pattern id="TrianglePattern"
	     patternUnits="userSpaceOnUse"
             x="0" y="0" width="50" height="50"
             viewBox="0 0 10 10" >
      <path d="M 0 0 L 7 0 L 3.5 7 z"
	    fill="plum"
	    stroke="blue" />
    </pattern> 
  </defs>

  <!-- The ellipse is filled using a triangle pattern paint server -->
  <ellipse fill="url(#TrianglePattern)"
	   stroke="black"
	   stroke-width="2"
           cx="150" cy="100" rx="125" ry="75" />
</svg>

IM makes the expected result, with "magick pattern.svg m.png". The output m.png is:

m

We can convert the SVG to an MVG text file, with "magick msvg:pattern.svg mvg:m.mvg":

push graphic-context
compliance "SVG"
fill "black"
fill-opacity 1
stroke "none"
stroke-width 1
stroke-opacity 1
fill-rule nonzero
viewbox 0 0 300 200
affine 1 0 0 1 0 0
#   Fill an ellipse using a pattern paint server.
push defs
push pattern "TrianglePattern" 0,0 50,50
push graphic-context
fill "plum"
stroke "blue"
path "M 0 0 L 7 0 L 3.5 7 z"
pop graphic-context
pop pattern
pop defs
push graphic-context
fill "url(#TrianglePattern)"
stroke "black"
stroke-width 2
ellipse 150,100 125,75 0,360
pop graphic-context
pop graphic-context

Note that "push pattern "TrianglePattern" 0,0 50,50" does not have "radial".

However, if we rasterise that file with "magick mvg:m.mvg m2.png", we get:

m2

The pattern has not been used. I suppose there is a bug somewhere.

For descriptions of MVG push, pop etc, see https://imagemagick.org/Usage/draw/#mvg .

snibgo avatar Aug 24 '23 01:08 snibgo

Instead of fill "url(#TrianglePattern)" try fill TrianglePattern (without enclosing) and remove quotation in pattern name. # sign and characters after it MVG interprets as wrong color definition. I thought that mvg-pattern is the same as in ghostscript, but it not. Just pattern of fill structure like pattern:bricks or pattern:checkerboard in cmd line. I also observe such a thing: the name of the template enclosed in single quotes, double quotes and without them lead to different results.

AlexSunnyMan avatar Aug 24 '23 03:08 AlexSunnyMan

Yes, that is better. When I edit two lines, to make a new file m2.mvg like this:

push graphic-context
compliance "SVG"
fill "black"
fill-opacity 1
stroke "none"
stroke-width 1
stroke-opacity 1
fill-rule nonzero
viewbox 0 0 300 200
affine 1 0 0 1 0 0
#   Fill an ellipse using a pattern paint server.
push defs
push pattern TrianglePattern 0,0 50,50    <== EDITED
push graphic-context
fill "plum"
stroke "blue"
path "M 0 0 L 7 0 L 3.5 7 z"
pop graphic-context
pop pattern
pop defs
push graphic-context
fill TrianglePattern    <== EDITED
stroke "black"
stroke-width 2
ellipse 150,100 125,75 0,360
pop graphic-context
pop graphic-context

... then the result from "magick mvg:m2.mvg m2a.png" is improved, but still not correct:

m2a

snibgo avatar Aug 24 '23 03:08 snibgo

The bad thing is that there is a problem with setting the transparency of the background of an mvg image, at least the base one, in relation to the canvas when using the -draw "image" operator, for example. The background of the resulting raster image is always white. If for example magick msvg:pict.svg -transparent white pict.miff works fine, then magick mvg:pict.mvg -transparent white pict.miff does not create transparency. Although the MIFF format fully supports it.

AlexSunnyMan avatar Aug 24 '23 11:08 AlexSunnyMan