7

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.
jrwren
  • 17,465
  • 8
  • 35
  • 56
clarkk
  • 27,151
  • 72
  • 200
  • 340

3 Answers3

5

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
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
0

i don't know if it's helpful, last day i have the same error :no magick++.h when i compile ImageMagick (not graphicsmagick). so i follows the steps in a official website to reinstall ImageMagick and finally i succeed.web:

1 http://www.imagemagick.org/script/install-source.php
2 http://www.imagemagick.org/script/magick++.php

i download the latest source code(ImageMagick6.9) in centOS-6.5 and then ./configure, make, make install. i hope it's helpful.

Mr C
  • 41
  • 6
0

On Ubuntu the GraphicsMagick++-config program you are using to get compile flags is correctly part of the same package which includes Magick++.h. Trying to run it tell you where to find it:

$ g++ gm_test.cpp -o gm_test `GraphicsMagick++-config --cppflags --cxxflags --ldflags --libs`
The program 'GraphicsMagick++-config' is currently not installed. You can install it by typing:
sudo apt-get install libgraphicsmagick++1-dev
gm_test.cpp:6:22: fatal error: Magick++.h: No such file or directory

compilation terminated.

So do what it says:

$ sudo apt-get install libgraphicsmagick++1-dev

Try the compile again and you will get a different error because GraphicsMagick++-config is linking to an uninstalled and unneeded library:

$ g++ gm_test.cpp -o gm_test `GraphicsMagick++-config --cppflags --cxxflags --ldflags --libs`
/usr/bin/ld: cannot find -lwebp
collect2: error: ld returned 1 exit status

You can manually specify the libs and the compile and link works:

$ g++ gm_test.cpp -o gm_test -I/usr/include/GraphicsMagick -Wall -g -fno-strict-aliasing -O2 -pthread  -lGraphicsMagick++ -lGraphicsMagick -ljbig
$ ./gm_test

Or you can install the required library:

$ sudo apt-get install libwebp-dev
jrwren
  • 17,465
  • 8
  • 35
  • 56