CImg Error : 'gm.exe' is not recognized as an internal or external command,

web2dev picture web2dev · Sep 11, 2013 · Viewed 7.8k times · Source

I am new to c++ programming , today i was trying to save an image using CImg . CImg is C++ Template Image Processing Library .

The basic code i wrote is(Please forgive any syntax erros , as copied part of my codes) :

#include "CImg.h"// Include CImg library header.
#include <iostream>

using namespace cimg_library;
using namespace std;

const int screen_size = 800;

//-------------------------------------------------------------------------------
//  Main procedure
//-------------------------------------------------------------------------------
int main()
{

CImg<unsigned char> img(screen_size,screen_size,1,3,20);
CImgDisplay disp(img, "CImg Tutorial");   
//Some drawing using img.draw_circle( 10, 10, 60, RED);
img.save("result.jpg"); // save the image    
return 0;   
}

But I cannot run my program as it says :

Invalid Parameter - 100%
'gm.exe' is not recognized as an internal or external command,
operable program or batch file.

This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.

[CImg] *** CImgIOException *** [instance(800,800,1,3,02150020,non-shared)] CImg<unsigned char>::save_other() : Failed to save file 'result.jpg'. Format is not natively supported, and no external commands succeeded.
terminate called after throwing an instance of 'cimg_library::CImgIOException'
  what():  [instance(800,800,1,3,02150020,non-shared)] CImg<unsigned char>::save_other() : Failed to save file 'result.jpg'. Format is not natively supported, and no external commands succeeded.

Though i can see the image , I cannot save it. After googling a bit i found people saying to install ImageMagick , i have installed it but no help . Some of the Forum says to compile against libjpeg, libpng, libmagick++. But i don't know how to compile against those libraries. I am using Eclipse CDT plugin to write C++ project . Please help me .

Answer

Maxim Georgievskiy picture Maxim Georgievskiy · Aug 20, 2017

I had the same error, and installing of GraphicsMagick (not ImageMagick) helped me.

I've downloaded and installed GraphicsMagick-1.3.26-Q8-win64-dll.exe from ftp://ftp.graphicsmagick.org/pub/GraphicsMagick/windows/. You may choose another one, if you need:

Note that the QuantumDepth=8 version (Q8) which provides industry standard 24/32 bit pixels consumes half the memory and about 30% less CPU than the QuantumDepth=16 version (Q16) which provides 48/64 bit pixels for high-resolution color. A Q8 version is fine for processing typical photos intended for viewing on a computer screen. If you are dealing with film, scientific, or medical images, use ICC color profiles, or deal with images that have limited contrast, then the Q16 version is recommended.

Important: during installation, don't remove checkbox "Update executable search path", which updates environment variable %PATH%, making gm.exe available from any place.

In my case, it was also required to install Ghostscript - which is highly recommended to install by GraphicsMagick. There is a link to x64 Ghostscript: https://sourceforge.net/projects/ghostscript/files/GPL%20Ghostscript/9.09/gs909w64.exe/download (I've put it here, because links from the GraphicMagick websites leads you to 32-bit only).

After that, it worked fine for me.