Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graphicsmagick C++ API

I want to use the C++ API for graphicsmagick

I need to convert image data directly from OpenCV and use graphicsmagick to save the file as tiff with group 4 compression

The command line

gm convert input -type bilevel -monochrome -compress group4 output.tif

Could anyone provide some code (see the above command line) to simply convert the output from OpenCV to tiff with group 4 compression

I'm new to C++ :)

testing graphicsmagick

I'm trying to make graphicsmagick work. Found a very simple code in the docs

I can't find Magick++.h

locate /Magick++.h returns nothing

but graphicsmagick is installed

# gm -version
GraphicsMagick 1.3.20 2014-08-16 Q8 http://www.GraphicsMagick.org/

code

/*
 *  Compile
 *  g++ gm_test.cpp -o gm_test `GraphicsMagick++-config --cppflags --cxxflags --ldflags --libs`
 */

#include <Magick++.h>

using namespace std;
using namespace Magick;

int main(int argc, char **argv){
    InitializeMagick(*argv);
    Image image( "100x100", "white" );
    image.pixelColor( 49, 49, "red" );
    image.write( "red_pixel.png" );
    return 0;
}

compile

# g++ gm_test.cpp -o gm_test `GraphicsMagick++-config --cppflags --cxxflags --ldflags --libs`
-bash: GraphicsMagick++-config: command not found
gm_test.cpp:6:22: fatal error: Magick++.h: No such file or directory
 #include <Magick++.h>
                      ^
compilation terminated.
like image 703
clarkk Avatar asked Dec 13 '15 18:12

clarkk


1 Answers

Updated Answer

Try looking for a file called GraphicsMagick-config under the directory where you installed GraphicsMagick like this:

find /usr -name "GraphicsMagick-config"

When you find that, you can ask it to tell you the compiler include flags and linker flags like this:

/usr/some/path/GraphicsMagick-config --cflags --libs

Then you can compile with:

gcc $(/usr/some/path/GraphicsMagick-config --cflags --libs) somefile.c -o somefile

Original Answer

Look in the directory where you installed GraphicsMagick for a file ending in .pc, which is the pkg-config file, e.g.

find /usr/local -iname "graphic*.pc"

Then pass this file to pkg-config to get the CFLAGS and LIBS you should use for compiling. So, if your graphicsmagick.pc is in /usr/local/Cellar/graphicsmagick/1.3.23/lib/pkgconfig/GraphicsMagick.pc, use:

pkg-config --cflags --libs /usr/local/Cellar/graphicsmagick/1.3.23/lib/pkgconfig/GraphicsMagick.pc

which will give you this:

/usr/local/Cellar/graphicsmagick/1.3.23/lib/pkgconfig/GraphicsMagick.pc
-I/usr/local/Cellar/graphicsmagick/1.3.23/include/GraphicsMagick -L/usr/local/Cellar/graphicsmagick/1.3.23/lib -lGraphicsMagick

Then you would compile with:

gcc $(pkg-config --cflags --libs somefile.c -o somefile
like image 196
Mark Setchell Avatar answered Sep 20 '22 17:09

Mark Setchell