SVG generation problems

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
sniceper
Posts: 2
Joined: 2011-08-01T04:48:29-07:00
Authentication code: 8675308

SVG generation problems

Post by sniceper »

Hello,

First, sorry for my english mistakes.

Well, i'm trying to generate some SVG images. Here is the interesting part of the code:

Code: Select all

    Image kod( Geometry(formatX+4*sizeP, formatY+4*sizeP), Color("white"));
    Image logo_image("/home/logos/" + logo);
    list<Drawable> ToDraw;                                                                                                          
    for (int i=0;i<tailleY;i++)
    {
        for (int j=0;j<tailleX;j++)
        {
            if (matrix[i][j])
            {
                ToDraw.push_back(DrawableCircle((double)(sizeP*j+2*sizeP+sizeP/2),(double)(sizeP*i+2*sizeP+sizeP/2),(double)(sizeP*j+2*sizeP+5),(double)(sizeP*i+2*sizeP+5)));
            }
        }
    }
    kod.fillColor("blue");
    kod.draw(ToDraw);
    kod.display();
    ToDraw.clear();
    if (secubit[0]) ToDraw.push_back(DrawableRectangle(2*sizeP-((sizeP/2)-1)+2*sizeP,   2*sizeP-((sizeP/2)-1)+2*sizeP,   2*sizeP-((sizeP/2)+1)+2*sizeP,   2*sizeP-((sizeP/2)+1)+2*sizeP));
    if (secubit[1]) ToDraw.push_back(DrawableRectangle(3*sizeP-((sizeP/2)-1)+2*sizeP,   2*sizeP-((sizeP/2)-1)+2*sizeP,   3*sizeP-((sizeP/2)+1)+2*sizeP,   2*sizeP-((sizeP/2)+1)+2*sizeP));
    if (secubit[2]) ToDraw.push_back(DrawableRectangle(4*sizeP-((sizeP/2)-1)+2*sizeP,   2*sizeP-((sizeP/2)-1)+2*sizeP,   4*sizeP-((sizeP/2)+1)+2*sizeP,   2*sizeP-((sizeP/2)+1)+2*sizeP));
    kod.fillColor("yellow");
    kod.draw(ToDraw);
    
  
        Geometry new_size(formatX-10*sizeP,formatY-10*sizeP);
        new_size.aspect(true);
        logo_image.resize(new_size);                                                                                                   
        kod.composite(logo_image,7*sizeP,7*sizeP,OverCompositeOp);
    

      kod.display();
      kod.write( "generated/" + ID +".svg");                                                                                                         

      return 0;
}
The code is supposed to Draw several Blue circles and three yellow squares around a logo (the image is a .svg). The generated file shows black circles (instead of blue) and the central logo is absent...
In order to fix it, i wrote two "kod.display()" to see the appearance of the file during the process. The command displays a correct image, with blue circles and the central logo... So it seems that the saving is the root of the problem.

I tried to save in JPG instead of SVG, it works too. So my question is: Why doesn't it want to save the colors and the logo when I generate a .SVG?


Thank you very much,
Sniceper.
Imaginatorium
Posts: 8
Joined: 2011-08-06T06:21:56-07:00
Authentication code: 8675308

Re: SVG generation problems

Post by Imaginatorium »

I hesitate to respond, since I am new to ImageMagick, but I think the answer is simple.

ImageMagick (and all the wrappers like Magick++) is a *bitmap graphics* package. It allows you to draw vectors, but only in bitmap form -- in other words, once you draw a circle it is converted to a lot of pixel values, and you cannot (directly) get back to the original vector specification. So it is not possible to save in a vector graphics format.

You need an SVG editing package (about which I know nothing, sorry)...
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: SVG generation problems

Post by anthony »

A word about Vector Image formats
http://www.imagemagick.org/Usage/formats/#vector
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
sniceper
Posts: 2
Joined: 2011-08-01T04:48:29-07:00
Authentication code: 8675308

Re: SVG generation problems

Post by sniceper »

Arg.. So I need another library to do what I want. I'll try any other library written in the webpage you sent me.

Thank you very much for replying,
sniceper.
Post Reply