Installing CXImage on Ubuntu
To use CXImage on Ubuntu, start by installing essential compilation tools and image format dependencies. Open a terminal and run:
sudo apt update && sudo apt upgrade -y
sudo apt install build-essential cmake libpng-dev libjpeg-dev libtiff-dev libgif-dev -y
These commands install GCC, CMake, and libraries required for handling PNG, JPEG, TIFF, and GIF formats.
Downloading CXImage Source Code
CXImage’s source code is hosted on GitHub. Clone the official repository (or a stable branch like main) using Git:
git clone https://github.com/cximage/cximage.git
cd cximage
Switch to the desired branch if necessary (e.g., git checkout main).
Compiling and Installing CXImage
Use CMake to generate build files and compile the source code:
mkdir build && cd build
cmake .. # Configure the build system
make -j$(nproc) # Compile with all available CPU cores
sudo make install # Install to system directories (/usr/local/include, /usr/local/lib)
This process compiles CXImage and installs it system-wide.
Configuring Environment Variables
To ensure your compiler locates CXImage’s headers and libraries, add the following to your ~/.bashrc (or ~/.zshrc):
export CPLUS_INCLUDE_PATH=/usr/local/include:$CPLUS_INCLUDE_PATH
export LIBRARY_PATH=/usr/local/lib:$LIBRARY_PATH
Run source ~/.bashrc to apply changes immediately.
Verifying Installation
Check if CXImage is installed correctly by compiling a test program. Create test_load_save.cpp:
#include <iostream>
#include "cximage.h"
int main() {
CXImage image;
if (!image.Load("input.jpg", CXIMAGE_FORMAT_JPG)) {
std::cerr << "Failed to load image!" << std::endl;
return 1;
}
if (!image.Save("output.png", CXIMAGE_FORMAT_PNG)) {
std::cerr << "Failed to save image!" << std::endl;
return 1;
}
std::cout << "Image converted successfully!" << std::endl;
return 0;
}
Compile and run:
g++ test_load_save.cpp -o test_load_save -lcximage
./test_load_save
If successful, this converts a JPEG to PNG and prints confirmation messages.
Basic Usage Examples
image.Resize(800, 600, FILTER_BOX) (fast resizing), rotate 90 degrees clockwise with image.Rotate(90), or crop a 300x300 region starting at (100, 100) with image.Crop(100, 100, 400, 400).Troubleshooting Common Issues
libpng-dev, libjpeg-dev) are installed./usr/local/lib is in LIBRARY_PATH and /usr/local/include is in CPLUS_INCLUDE_PATH./opt/cximage), specify paths during compilation with -I/opt/cximage/include and -L/opt/cximage/lib.