From 13ce0ac4e10c055bf4468457807df961fb3eac14 Mon Sep 17 00:00:00 2001 From: apocelipes Date: Fri, 20 Dec 2024 16:44:27 +0800 Subject: [PATCH] Fix save images Fixes #437. --- CImg.h | 74 ++++++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 62 insertions(+), 12 deletions(-) diff --git a/CImg.h b/CImg.h index aa1e01ab..48dbea0d 100644 --- a/CImg.h +++ b/CImg.h @@ -58333,7 +58333,11 @@ namespace cimg_library { cimg::graphicsmagick_path(), s_filename.data(), CImg::string(filename_tmp)._system_strescape().data()); - cimg::system(command,cimg::graphicsmagick_path()); + if (cimg::system(command,cimg::graphicsmagick_path()) != 0) + throw CImgIOException(_cimg_instance + "load_graphicsmagick_external(): Failed to load file '%s' with external command 'gm'.", + cimg_instance, + filename); if (!(file=cimg::std_fopen(filename_tmp,"rb"))) { cimg::fclose(cimg::fopen(filename,"r")); throw CImgIOException(_cimg_instance @@ -58390,7 +58394,11 @@ namespace cimg_library { cimg::gunzip_path(), CImg::string(filename)._system_strescape().data(), CImg::string(filename_tmp)._system_strescape().data()); - cimg::system(command); + if (cimg::system(command) != 0) + throw CImgIOException(_cimg_instance + "load_gzip_external(): Failed to load file '%s' with external command 'gunzip'.", + cimg_instance, + filename); if (!(file=cimg::std_fopen(filename_tmp,"rb"))) { cimg::fclose(cimg::fopen(filename,"r")); throw CImgIOException(_cimg_instance @@ -58477,7 +58485,12 @@ namespace cimg_library { !cimg::strcasecmp(cimg::split_filename(filename),"pdf")?" -density 400x400":"", s_filename.data(), CImg::string(filename_tmp)._system_strescape().data()); - cimg::system(command,magick_path); + if (cimg::system(command,magick_path) != 0) + throw CImgIOException(_cimg_instance + "load_imagemagick_external(): Failed to load file '%s' with " + "external command 'magick/convert'.", + cimg_instance, + filename); if (!(file=cimg::std_fopen(filename_tmp,"rb"))) { cimg::fclose(cimg::fopen(filename,"r")); throw CImgIOException(_cimg_instance @@ -62149,7 +62162,11 @@ namespace cimg_library { cimg::gzip_path(), CImg::string(filename_tmp)._system_strescape().data(), CImg::string(filename)._system_strescape().data()); - cimg::system(command,cimg::gzip_path()); + if (cimg::system(command,cimg::gzip_path()) != 0) + throw CImgIOException(_cimg_instance + "save_gzip_external(): Failed to save file '%s' with external command 'gzip'.", + cimg_instance, + filename); file = cimg::std_fopen(filename,"rb"); if (!file) throw CImgIOException(_cimg_instance @@ -62207,7 +62224,11 @@ namespace cimg_library { cimg::graphicsmagick_path(),quality, CImg::string(filename_tmp)._system_strescape().data(), CImg::string(filename)._system_strescape().data()); - cimg::system(command,cimg::graphicsmagick_path()); + if (cimg::system(command,cimg::graphicsmagick_path()) != 0) + throw CImgIOException(_cimg_instance + "save_graphicsmagick_external(): Failed to save file '%s' with external command 'gm'.", + cimg_instance, + filename); file = cimg::std_fopen(filename,"rb"); if (!file) throw CImgIOException(_cimg_instance @@ -62263,7 +62284,12 @@ namespace cimg_library { magick_path,quality, CImg::string(filename_tmp)._system_strescape().data(), CImg::string(filename)._system_strescape().data()); - cimg::system(command,magick_path); + if (cimg::system(command,magick_path) != 0) + throw CImgIOException(_cimg_instance + "save_imagemagick_external(): Failed to save file '%s' with " + "external command 'magick/convert'.", + cimg_instance, + filename); file = cimg::std_fopen(filename,"rb"); if (!file) throw CImgIOException(_cimg_instance @@ -62302,7 +62328,11 @@ namespace cimg_library { cimg::medcon_path(), CImg::string(filename)._system_strescape().data(), CImg::string(filename_tmp)._system_strescape().data()); - cimg::system(command,cimg::medcon_path()); + if (cimg::system(command,cimg::medcon_path()) != 0) + throw CImgIOException(_cimg_instance + "save_medcon_external(): Failed to save file '%s' with external command 'medcon'.", + cimg_instance, + filename); std::remove(filename_tmp); cimg::split_filename(filename_tmp,body); cimg_snprintf(filename_tmp,filename_tmp._width,"%s.img",body._data); @@ -65935,7 +65965,11 @@ namespace cimg_library { cimg::ffmpeg_path(), CImg::string(filename)._system_strescape().data(), CImg::string(filename_tmp2)._system_strescape().data()); - cimg::system(command,cimg::ffmpeg_path()); + if (cimg::system(command,cimg::ffmpeg_path()) != 0) + throw CImgIOException(_cimglist_instance + "load_ffmpeg_external(): Failed to open file '%s' with external command 'ffmpeg'.", + cimglist_instance, + filename); const unsigned int omode = cimg::exception_mode(); cimg::exception_mode(0); assign(); @@ -66062,7 +66096,11 @@ namespace cimg_library { cimg::gunzip_path(), CImg::string(filename)._system_strescape().data(), CImg::string(filename_tmp)._system_strescape().data()); - cimg::system(command,cimg::gunzip_path()); + if (cimg::system(command,cimg::gunzip_path()) != 0) + throw CImgIOException(_cimglist_instance + "load_gzip_external(): Failed to open file '%s'.", + cimglist_instance, + filename); if (!(file=cimg::std_fopen(filename_tmp,"rb"))) { cimg::fclose(cimg::fopen(filename,"r")); throw CImgIOException(_cimglist_instance @@ -66517,7 +66555,11 @@ namespace cimg_library { cimg_for(_command,p,char) if (!*p) *p = ' '; _command.back() = 0; - cimg::system(_command,cimg::imagemagick_path()); + if (cimg::system(_command,cimg::imagemagick_path()) != 0) + throw CImgIOException(_cimglist_instance + "save_gif_external(): Failed to save file '%s' with external command 'magick/convert'.", + cimglist_instance, + filename); file = cimg::std_fopen(filename,"rb"); if (!file) throw CImgIOException(_cimglist_instance @@ -66964,7 +67006,11 @@ namespace cimg_library { cimg::gzip_path(), CImg::string(filename_tmp)._system_strescape().data(), CImg::string(filename)._system_strescape().data()); - cimg::system(command,cimg::gzip_path()); + if (cimg::system(command,cimg::gzip_path()) != 0) + throw CImgIOException(_cimglist_instance + "save_gzip_external(): Failed to save file '%s' with external command 'gzip'.", + cimglist_instance, + filename); file = cimg::std_fopen(filename,"rb"); if (!file) throw CImgIOException(_cimglist_instance @@ -67168,7 +67214,11 @@ namespace cimg_library { fps,CImg::string(filename_tmp)._system_strescape().data(), _codec,bitrate,fps, CImg::string(filename)._system_strescape().data()); - cimg::system(command,cimg::ffmpeg_path()); + if (cimg::system(command,cimg::ffmpeg_path()) != 0) + throw CImgIOException(_cimglist_instance + "save_ffmpeg_external(): Failed to save file '%s' with external command 'ffmpeg'.", + cimglist_instance, + filename); file = cimg::std_fopen(filename,"rb"); if (!file) throw CImgIOException(_cimglist_instance