GreycLab / CImg

The CImg Library is a small and open-source C++ toolkit for image processing
http://cimg.eu
Other
1.49k stars 285 forks source link

Prefer to use magick rather than convert #418

Closed apocelipes closed 4 months ago

apocelipes commented 4 months ago

convert is marked as deprecated since ImageMagick7, and now calling "convert" will get a noisy warning message:

WARNING: The convert command is deprecated in IMv7, use "magick"

My version of ImageMagick: ImageMagick 7.1.1-33 Q16-HDRI x86_64 22263 https://imagemagick.org

This warning can be avoided by using magick whenever possible.

On Windows, CImg will use magick firstly:

if (win_searchpath("magick.exe",s_path,s_path._width)) path_found = true;

I think the same strategy should be used on Linux as well.

I'd like to add a helper function to find if a command is in the $PATH and use magick whenever possible, the code looks like this:

        std::strcpy(s_path,"./magick");
        if ((file=cimg::std_fopen(s_path,"r"))!=0) { cimg::fclose(file); path_found = true; }
        if (!path_found) {
          std::strcpy(s_path,"./convert");
          if ((file=cimg::std_fopen(s_path,"r"))!=0) { cimg::fclose(file); path_found = true; }
        }
+       if (!path_found) {
+         std::strcpy(s_path, "magick");
+         if (posix_searchpath("magick")) path_found = true;
+       }
        if (!path_found) std::strcpy(s_path,"convert");

If we cannot find "magick", we will fall back to "convert". The full code can be seen in the associated PR.