在Debian中集成cxImage與其他工具,可按以下步驟操作:
sudo apt update
sudo apt install build-essential libpng-dev libjpeg-dev libtiff-dev libgif-dev
git clone https://github.com/antirez/cxImage.git
cd cxImage
mkdir build && cd build
cmake ..
make
sudo make install
將庫文件路徑添加到~/.bashrc:
echo 'export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH' >> ~/.bashrc
echo 'export CPLUS_INCLUDE_PATH=/usr/local/include:$CPLUS_INCLUDE_PATH' >> ~/.bashrc
source ~/.bashrc
在項目中包含cxImage頭文件,鏈接庫文件:
#include "cxImage.h"
// 編譯時添加 -lcximage 選項
g++ your_program.cpp -o output -lcximage
通過ctypes調用cxImage的C接口(需先安裝python3-dev):
import ctypes
lib = ctypes.CDLL('/usr/local/lib/libcximage.so')
# 調用庫函數(需根據cxImage API編寫)
# cxImage保存為臨時文件,再由ImageMagick轉換
./your_cximage_program input.jpg output.png
magick output.png output.webp
for img in *.jpg; do
./your_cximage_program "$img" "processed_$img"
magick "processed_$img" "webp/$(basename "$img" .jpg).webp"
done
cmake參數指定庫路徑。LD_LIBRARY_PATH是否包含/usr/local/lib,可通過ldconfig更新庫緩存。libcximage-dev包(若可用),避免手動編譯的兼容性問題。