Page 1 of 3

Checking out the new GradientImage in 6.4.4-2

Posted: 2008-10-08T16:38:36-07:00
by rmagick
I'm investigating the new GradientImage method in 6.4.4-2, with the new RadialGradient support. I've created a little montage so I can see the difference between the different SpreadMethod values. Here it is:

Image

I'm not able to see much difference in the LinearGradient results. Should I? Or is that limited to the RadialGradient type?

Re: Checking out the new GradientImage in 6.4.4-2

Posted: 2008-10-08T17:57:43-07:00
by magick
Proper use of the gradient requires SVG, MVG, or the drawing API. The gradient: and radial-gradient: formats are not very useful with only two stop colors and with offsets that span the image width and height. We thought about allowing defines (-define) to alter how these formats behave but we would quickly end up replicating what we already do with the rendering engine.

As an aside, Anthony pointed out the linear gradients are on a 45 degree angle which is a bug. We have a patch in the Subversion trunk and will include it of course in the next point release within a week or two.

As an aside, for the RMagick community (in case you missed it)-- the latest versions of ImageMagick address performance bottlenecks and includes support for parallel processing on dual and quad-core processors. Existing RMagick scripts should, in most cases, show a significant speed up.

Re: Checking out the new GradientImage in 6.4.4-2

Posted: 2008-10-08T18:12:18-07:00
by rmagick
Thanks for the quick reply!

I didn't miss it - RMagick 2.7.0 supports all versions of ImageMagick from 6.3.0 to 6.4.4-2.

Re: Checking out the new GradientImage in 6.4.4-2

Posted: 2008-10-10T19:55:49-07:00
by fmw42
rmagick wrote:I'm investigating the new GradientImage method in 6.4.4-2, with the new RadialGradient support. I've created a little montage so I can see the difference between the different SpreadMethod values. Here it is:

Image

I'm not able to see much difference in the LinearGradient results. Should I? Or is that limited to the RadialGradient type?
I have been trying to figure out how to generate these gradients using -draw, but am getting nowhere. The docs on the MVG page are not explanatory enough. Can you identify the command line commands one uses with -draw to generate the examples you have here.

Thanks.

Re: Checking out the new GradientImage in 6.4.4-2

Posted: 2008-10-10T20:27:40-07:00
by magick
Find or generate a very simple SVG gradient and convert it to MVG to see out it is defined in MVG:
  • convert simple-gradient.svg simple-gradient.mvg
    cat simple-gradient.mvg
P.S. There is a patch in ImageMagick 6.4.4-4 that fixes the bug in ImageMagick 6.4.4-3 gradients.

Re: Checking out the new GradientImage in 6.4.4-2

Posted: 2008-10-11T06:58:07-07:00
by rmagick
I can't help but think I'm overlooking something really obvious.

I'm getting the message "no image vector graphics `test.mvg'. See below. I looked at coders/mvg.c, which sends this message if the GetImageArtifact function returns NULL for the "MVG" key.

Code: Select all

tim@linux:~$ convert test.svg test.mvg
convert: no image vector graphics `test.mvg'.
tim@linux:~$ ls test.svg
test.svg
tim@linux:~$ cat test.svg
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">

<svg width="100%" height="100%" version="1.1" xmlns="http://www.w3.org/2000/svg">
<defs>
  <radialGradient id="grey_blue" cx="50%" cy="50%" r="50%" fx="50%" fy="50%">
    <stop offset="0%" style="stop-color:rgb(200,200,200); stop-opacity:0"/>
    <stop offset="100%" style="stop-color:rgb(0,0,255); stop-opacity:1"/>
  </radialGradient>
</defs>
<ellipse cx="230" cy="200" rx="110" ry="100" style="fill:url(#grey_blue)"/>
</svg>

tim@linux:~$ convert -list configure

Path: /home/software/ImageMagick-6.4.4/lib/ImageMagick-6.4.4/config/configure.xml

Name          Value
-------------------------------------------------------------------------------
CC            gcc -std=gnu99
CFLAGS        -I/usr/include/lqr-1 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include -g -Wall -W -pthread
CONFIGURE     ./configure  'CFLAGS=-g' '--enable-shared' '--disable-static' '--with-modules' '--with-gs-font-dir=/usr/share/fonts/type1/gsfonts' '--with-lqr' '--enable-cipher' '--disable-openmp' '--with-quantum-depth=16' '--without-perl' '--without-magick-plus-plus' '--prefix=/home/software/ImageMagick-6.4.4'
COPYRIGHT     Copyright (C) 1999-2008 ImageMagick Studio LLC
CPPFLAGS      -I/home/software/ImageMagick-6.4.4/include/ImageMagick
CXX           g++
CXXFLAGS      -g -O2 -Wall -W -pthread
DEFS          -DHAVE_CONFIG_H
DELEGATES     bzlib fontconfig freetype gs jpeg lcms lqr png rsvg tiff x11 xml wmf zlib
DISTCHECK_CONFIG_FLAGS 'CFLAGS=-g' --disable-deprecated --with-quantum-depth=16 --with-umem=no --with-autotrace=no --with-fontpath= --with-gs-font-dir=/usr/share/fonts/type1/gsfonts
EXEC-PREFIX   /home/software/ImageMagick-6.4.4
HOST          i686-pc-linux-gnu
LDFLAGS       -L/home/software/ImageMagick-6.4.4/lib -lfreetype -lz
LIB_VERSION   0x644
LIB_VERSION_NUMBER 6,4,4,4
LIBS          -lMagickCore -llcms -ltiff -lfreetype -ljpeg -L/usr/lib/lqr-1 -llqr-1 -lglib-2.0 -lfontconfig -lXext -lSM -lICE -lX11 -lbz2 -lz -lm -lpthread
NAME          ImageMagick
PCFLAGS
PREFIX        /home/software/ImageMagick-6.4.4
QuantumDepth  16
RELEASE_DATE  2008-10-10
VERSION       6.4.4
WEBSITE       http://www.imagemagick.org
tim@linux:~$

Re: Checking out the new GradientImage in 6.4.4-2

Posted: 2008-10-11T14:20:46-07:00
by magick
You need to build ImageMagick without rsvg support otherwise SVG rendering does not use the internal SVG renderer. Add something like --without-rsvg to your configure command line or edit coders/svg.c and change MAGICKCORE_RSVG_DELEGATE to something like MAGICKCORE_NO_RSVG_DELEGATE. In the mean-time ImageMagick generates this MVG for your file:

Code: Select all

push graphic-context
  viewbox 0 0 1000 1000
  affine 1 0 0 1 -0 -0
  push defs
    push gradient 'grey_blue' radial 500,500 500,500 9.5
      stop-color 'rgb(200,200,200)' 0%
      stop-color 'rgb(0,0,255)' 100%
    pop gradient
  pop defs
  push graphic-context
    fill 'url(#grey_blue)'
    ellipse 230,200 110,100 0,360
  pop graphic-context
pop graphic-context
However, it does not render the radial gradient properly. We're investigating now.

Re: Checking out the new GradientImage in 6.4.4-2

Posted: 2008-10-11T16:13:50-07:00
by fmw42
magick wrote:Find or generate a very simple SVG gradient and convert it to MVG to see out it is defined in MVG:
  • convert simple-gradient.svg simple-gradient.mvg
    cat simple-gradient.mvg
P.S. There is a patch in ImageMagick 6.4.4-4 that fixes the bug in ImageMagick 6.4.4-3 gradients.
I tried copying the example radgrad01 at http://www.w3.org/TR/SVG/pservers.html#RadialGradients to file radgrad1.svg and running it using 6.4.4.-4 IM Q16 Mac OSX Tiger, but it did not render the gradient.

The example from the referenced page was:
Image

But what I got from running that file was:
convert radgrad1.svg radgrad1.png
Image

Is there still a bug or do I need to install some delegate library?

Re: Checking out the new GradientImage in 6.4.4-2

Posted: 2008-10-11T16:49:29-07:00
by magick
We're investigating now. We will need a day or two.

Re: Checking out the new GradientImage in 6.4.4-2

Posted: 2008-10-12T18:44:10-07:00
by magick
The gradient drawing method is working perfectly-- what is missing is the finishing touches on the gradient parser that sets the GradientInfo structure with multiple color stops. A fix for this problem is on our to-do list.

Re: Checking out the new GradientImage in 6.4.4-2

Posted: 2008-10-14T23:59:10-07:00
by anthony
If you have the RSVG library configuration installed you should be able to force IM to use the internal method for a SVG image, by prefixing it with MSVG:

EG:
convert msvg:diagonal.svg diagonal_msvg.gif

http://www.imagemagick.org/Usage/draw/#svg

However I have yet to see the effects of the new gradient, in images.
I may have to build a non RSVG version to check it out, even though it should be availabel via the MSVG: input coder.

Re: Checking out the new GradientImage in 6.4.4-2

Posted: 2008-10-15T22:21:12-07:00
by anthony
magick wrote:The gradient: and radial-gradient: formats are not very useful with only two stop colors and with offsets that span the image width and height.
Can the image generator radial-gradient: be modified to produce a circular gradient more like
Image
that is the gradient goes from center to top edge, rather than the current center to corner?

That way users can generate a complete circular gradient and trim it is desired, rather than the clipped version that is currently generated.

In the mean time I have added some examples in the Gradient Canvas area of IM examples. It should appear sometime soon at
http://www.imagemagick.org/Usage/canvas ... l-gradient

Re: Checking out the new GradientImage in 6.4.4-2

Posted: 2008-10-15T23:10:21-07:00
by fmw42
anthony wrote:
magick wrote:The gradient: and radial-gradient: formats are not very useful with only two stop colors and with offsets that span the image width and height.
Can the image generator radial-gradient: be modified to produce a circular gradient more like
Image
that is the gradient goes from center to top edge, rather than the current center to corner?

That way users can generate a complete circular gradient and trim it is desired, rather than the clipped version that is currently generated.

In the mean time I have added some examples in the Gradient Canvas area of IM examples. It should appear sometime soon at
http://www.imagemagick.org/Usage/canvas ... l-gradient
This is great. Thanks. I did not know that this was available as a direct IM option without -draw.

Just some ideas to think about. I don't know about the complexity of doing so, however and not a high priority.

1) Actually both options would be nice --- max at edge and max at corner.

2) When the image is not square, however, you now get the gradient to max dimension. Options to min dimension and to make an ellipse would also be nice. The latter may be more useful.

FYI: This feature (radial gradient) has potential utility in generating frequency domain filters (if we ever get FFT development into IM).

Re: Checking out the new GradientImage in 6.4.4-2

Posted: 2008-10-16T00:28:22-07:00
by anthony
Hold on Fred. As Cristy said before, it would be hard to figure out an option set that would continue to allow easy use (like gradient: does currently) with all the numerous options that users may like to have available.

I'm not saying that it isn't possible, just a lot more work. If you can come up with some structure for the original 'gradient:' with 'styles', 'color-stops' and 'repeat' methods. that still allows the current 'easy to use' defination, especially if it better corresponds with SVG, then maybe, someone might take time to implement it.

At the moment Cristy is just trying to get SVG and MVG gradients working, which is a more important first step. The radial-gradient: feature was just something he mentioned above and I took a look at. I was suprised it had even been added.

I just felt changing the outer point from a corner to some fixed edge (top would be most logical) would at least allow users to better define the radius, and make the whole gradient visible. And it was better for such a change to be made as early as posible.

And any other 'options' would have entailed a lot more work, and make it different to the other two gradient image generators gradient: and plasma: which is basically a fractal color distortion on top of the normal gradient: base image.

I too like to see a lot more options. But I prefer to get the SVG gradient working for most. However if Cristy wants I'll jump into the code radial-gradient code and change it as I suggested. Or if you can come up with a good 'options' method. I'll gladly try to implement it to. But most importantly it must fall back to easy to use, just as gradient: has been for the last decade.

Think about it and wour out some scheme to implement it using a simple but expandable string.

Remember currently you can specify a gradient as
''
'{one_color}'
'{one_color}-{two_color}'
See IM examples for an indication of how these three styles currently work.

Re: Checking out the new GradientImage in 6.4.4-2

Posted: 2008-10-16T06:18:06-07:00
by magick
Anthony, feel free to fix the radial gradient to default to something sensible. Just make sure you restrict your patches to GradientImage() rather than DrawGradientImage().

The best way to add options is to use the -define or -set (e.g. -define radial-gradient:radius=0.2).

Folks, we're working on the gradient parser in the drawing renderer but it may take some time given the current demands on our time. Stand by...