FreeImage is an Open Source library project for developers who would like to support popular graphics image formats like PNG, BMP, JPEG, TIFF and others as needed by today's multimedia applications. FreeImage is easy to use, fast, multithreading safe, and cross-platform (works with Windows, Linux and Mac OS X).
- Numerous Sub-Dependancy patches (Security/Bugs/Latest)
- With patches applied from nVidia Devs and OpenSource additions
- CMake Build ability allowing compiling easily for all targets and platforms
Thanks to it's ANSI C interface, FreeImage is usable in many languages including C, C++, VB, C#, Delphi, Java and also in common scripting languages such as Perl, Python, PHP, TCL, Lua or Ruby. The library comes in two versions: a binary DLL distribution that can be linked against any WIN32/WIN64 C/C++ compiler and a source distribution. Built with CMake for Windows, Linux, Mac OS X and other systems - see Building this fork below, including generating Visual Studio project files.
Loading a PNG, a GIF and a JPEG from scratch in C++ means three different APIs (libpng, giflib-or-hand-rolled-LZW, libjpeg), three different error-handling conventions, and three sets of build flags to get right across platforms. FreeImage wraps all of the libraries below behind one API - one FreeImage_Load()/FreeImage_Save() pair, one pixel format model (FIBITMAP), one metadata API (EXIF/IPTC/XMP) - so format-specific code doesn't leak into the rest of your application. Swapping a PNG for a WebP, or reading a RAW file the same way you read a BMP, is a one-line change rather than a new dependency.
This fork additionally builds the whole stack (FreeImage plus every bundled library) from one CMakeLists.txt, so find_package(FreeImage) is the only thing a consuming CMake project needs - see Using compiled binaries below.
Formats implemented directly in FreeImage's own plugin code (no external library): BMP, ICO, TARGA/TGA, PCX, DDS, GIF, PSD, PICT, PFM, RAS/Sun Raster, SGI, XBM, XPM, Amiga IFF/LBM, Kodak PCD, PNM/PBM/PGM/PPM, CUT, and WBMP.
Everything else is backed by a bundled, patched copy of the format's reference library - each can also be linked against a system copy instead via the matching USE_SYSTEM_*/BUILD_* CMake option (see CMakeLists.txt):
| Formats | Library | Bundled version |
|---|---|---|
| PNG | libpng (+ zlib) | 1.6.58 (zlib 1.3.2) |
| JPEG | libjpeg (IJG) | 10 |
| TIFF | libtiff | 4.7.1 |
| JPEG 2000 (J2K/JP2) | OpenJPEG | 2.5.4 |
| OpenEXR (HDR) | OpenEXR (+ Imath) | 3.3.13 (Imath 3.1.12) |
| WebP | libwebp | current (see Source/LibWebP) |
| Camera RAW | LibRaw | 0.22.1 |
| JPEG-XR (Windows by default, see Building this fork) | jxrlib | - |
https://sourceforge.net/projects/freeimage Original library can be found : https://freeimage.sourceforge.io
By default, JPEG-XR support is only included on Windows, but not on other platforms.
cmake . -B cmake-build
cmake --build cmake-build # On Linux, add -j$(nproc) for multicore buildLinux (gcc) / macOS (clang)
cmake -S . -B build -DBUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Debug
cmake --build build -- -j$(nproc) # macOS: -j$(sysctl -n hw.ncpu)Windows (MSVC, Visual Studio toolchain)
cmake -S . -B build -DBUILD_TESTS=ON -DCMAKE_CXX_STANDARD=17
cmake --build build --config DebugSee Generate Visual Studio project files below for opening the solution directly in the IDE.
Windows (MinGW, e.g. a toolchain already on PATH)
cmake -S . -B build -DBUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Debug -G "MinGW Makefiles"
cmake --build buildWindows (MinGW-w64 via MSYS2, see #30)
From an MSYS2 MINGW64 shell:
pacman -S mingw-w64-x86_64-toolchain mingw-w64-x86_64-cmake mingw-w64-x86_64-ninja
cmake -S . -B build -G Ninja -DBUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Debug
cmake --build buildPlain make (Linux, no CMake)
make -j$(nproc)cmake --preset vs2022 # or: cmake --preset vs2026Generates a full solution under build-vs2022/ (or build-vs2026/) - open FreeImage.sln from there in Visual Studio. See CMakePresets.json for the exact generator/options used.
cmake . -B cmake-build-debug -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=install_dir
cmake --build cmake-build-debug --config Debug --target install # Linux: -j$(nproc)
cmake . -B cmake-build-release -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=install_dir
cmake --build cmake-build-release --config Release --target install # Linux: -j$(nproc)Now install_dir contains the compiled binaries for debug and release, as well as the header file and the CMake Config files.
First, build and install it like explained above.
Then, in another project add the following CMake code:
set(CMAKE_PREFIX_PATH <freeimage_install_location>)
find_package(FreeImage CONFIG REQUIRED)
...
target_link_libraries(<your_target> PRIVATE FreeImage::FreeImage)For find_package to work, simply set CMAKE_PREFIX_PATH to the directory where the compiled binaries are installed (the install_dir folder from above).
cmake . -B cmake-build-debug -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON
cmake --build cmake-build-debug --config Debug # Linux: -j$(nproc)
ctest --test-dir cmake-build-debug -C Debug # Optionally --rerun-failed --output-on-failureThis ctest command only works with CMake 3.20 or higher. For earlier versions, you must
cdintocmake-build-debugand call ctest without--test-dir cmake-build-debug.