This should do:
Code: Select all
Magick::Image image;
std::ostringstream svg;
svg << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><svg:svg version=\"1.1\" xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"612.0000\" height=\"792.0000\" ><svg:g id=\"Layer1000\" ><svg:path d=\"M248.5722,313.5199 C286.0311,351.3391 251.5994,444.2915 351.4266,435.6785 C135.3714,503.8092 162.7146,226.8327 248.5722,313.5199 Z\" style=\"fill-rule: evenodd; fill: #00ff00; \"/><svg:path d=\"M355.4542,316.5640 C357.2108,354.8566 293.9365,387.9004 351.4352,431.4938 C203.0981,363.5886 351.4299,228.7934 355.4542,316.5640 Z\" style=\"fill-rule: evenodd; fill: #0000ff; \"/><svg:path d=\"M419.1075,365.6919 C399.8818,388.5695 346.1535,374.0783 356.0787,429.4467 C306.9301,312.1468 463.1757,313.2551 419.1075,365.6919 Z\" style=\"fill-rule: evenodd; fill: #ff6600; \"/><svg:path d=\"M365.1285,431.9341 C334.9629,472.8561 230.5034,460.9752 204.9837,433.2682 C220.1241,489.2392 342.5426,562.8036 399.0555,427.3596 C402.1712,419.8979 406.3505,411.6497 411.3621,413.3209 L424.0858,417.1050 L417.1878,404.8308 C395.0314,365.4028 376.7381,416.1852 365.1285,431.9341 Z\" style=\"fill-rule: evenodd; fill: #0000ff; \"/></svg:g><svg:path d=\"M90.5681,206.8804 L90.5681,585.1196 L521.4319,585.1196 L521.4319,206.8804 L90.5681,206.8804 Z\" style=\"fill: none; \"/></svg:svg>";
Magick::Blob blob(static_cast<const void *>(svg.str().c_str()),svg.str().size());
try {
image.read(blob);
}
catch(Magick::Error &error) {
std::cout << error.what() << std::endl;
}
std::cout << image.columns() << "x" << image.rows() << std::endl;
Works on Linux, but not Windows.
I used qtcreator (I'm lazy), complete project if you want:
Code: Select all
QT += core
QT -= gui
TARGET = magicksvg
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
SOURCES += main.cpp
CONFIG += link_pkgconfig
PKGCONFIG += Magick++
QMAKE_CXXFLAGS += `pkg-config Magick++ --cflags`
LIBS += `pkg-config Magick++ --libs --static`
win32: LIBS += -lws2_32
Code: Select all
#include <QCoreApplication>
#include <iostream>
#include <sstream>
#include <Magick++.h>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
Magick::Image image;
std::ostringstream svg;
svg << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><svg:svg version=\"1.1\" xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" width=\"612.0000\" height=\"792.0000\" ><svg:g id=\"Layer1000\" ><svg:path d=\"M248.5722,313.5199 C286.0311,351.3391 251.5994,444.2915 351.4266,435.6785 C135.3714,503.8092 162.7146,226.8327 248.5722,313.5199 Z\" style=\"fill-rule: evenodd; fill: #00ff00; \"/><svg:path d=\"M355.4542,316.5640 C357.2108,354.8566 293.9365,387.9004 351.4352,431.4938 C203.0981,363.5886 351.4299,228.7934 355.4542,316.5640 Z\" style=\"fill-rule: evenodd; fill: #0000ff; \"/><svg:path d=\"M419.1075,365.6919 C399.8818,388.5695 346.1535,374.0783 356.0787,429.4467 C306.9301,312.1468 463.1757,313.2551 419.1075,365.6919 Z\" style=\"fill-rule: evenodd; fill: #ff6600; \"/><svg:path d=\"M365.1285,431.9341 C334.9629,472.8561 230.5034,460.9752 204.9837,433.2682 C220.1241,489.2392 342.5426,562.8036 399.0555,427.3596 C402.1712,419.8979 406.3505,411.6497 411.3621,413.3209 L424.0858,417.1050 L417.1878,404.8308 C395.0314,365.4028 376.7381,416.1852 365.1285,431.9341 Z\" style=\"fill-rule: evenodd; fill: #0000ff; \"/></svg:g><svg:path d=\"M90.5681,206.8804 L90.5681,585.1196 L521.4319,585.1196 L521.4319,206.8804 L90.5681,206.8804 Z\" style=\"fill: none; \"/></svg:svg>";
Magick::Blob blob(static_cast<const void *>(svg.str().c_str()),svg.str().size());
try {
image.read(blob);
}
catch(Magick::Error &error) {
std::cout << error.what() << std::endl;
}
std::cout << image.columns() << "x" << image.rows() << std::endl;
return 1;
}