ubuntu系统自带的imagemagick没有c++函数库,需要能重新下载一个新一点的库,重新编译并且安装
官网详细教程:https://imagemagick.org/script/install-source.php
下载:
git clone https://github.com/ImageMagick/ImageMagick.git ImageMagick-7.1.1
此时删除原有的imagemagick
sudo apt-get remove imagemagick
进入目录和安装:
cd ImageMagick-7.1.1
./configure --with-magick-plus-plus
make
sudo make install
注意:
./configure 如果不带–with-magick-plus-plus,只会安装命令行之类的工具,不会安装c++函数库。
配置动态链接器运行时绑定:
sudo ldconfig /usr/local/lib
验证:
/usr/local/bin/convert logo: logo.gif
convert -version
要进行更全面的测试,请运行ImageMagick验证套件:
make check
我在 Ubuntu 14.04 上,默认安装了 ImageMagick 6.7.7-10。我需要在 C++ 项目中使用Magick++
,ImageMagick 的 C++ API,但我不知道它位于何处。我怎么知道我是否拥有它,如果我没有,获得它的最佳方式是什么?
需要安装一些依赖:
sudo apt-get install graphicsmagick-libmagick-dev-compat
或者:
sudo apt-get install libgraphicsmagick1-dev
因为:
% apt-rdepends graphicsmagick-libmagick-dev-compat | grep magick
Reading package lists... Done
Building dependency tree
Reading state information... Done
graphicsmagick-libmagick-dev-compat
Depends: libgraphics-magick-perl
Depends: libgraphicsmagick++1-dev
Depends: libgraphicsmagick1-dev
libgraphics-magick-perl
Depends: libgraphicsmagick3 (>= 1.3.5)
libgraphicsmagick3
libgraphicsmagick++1-dev
Depends: libgraphicsmagick++3 (= 1.3.20-4)
Depends: libgraphicsmagick1-dev
libgraphicsmagick++3
Depends: libgraphicsmagick3 (>= 1.3.15)
libgraphicsmagick1-dev
Depends: libgraphicsmagick3 (= 1.3.20-4)
% apt-rdepends libgraphicsmagick1-dev | grep magick
Reading package lists... Done
Building dependency tree
Reading state information... Done
libgraphicsmagick1-dev
Depends: libgraphicsmagick3 (= 1.3.20-4)
libgraphicsmagick3
sudo apt-get install libmagick++-dev
此时再进行查找:
sudo apt-file find Magick++.h
存在相关的:
/usr/include/ImageMagick/Magick++.h
[100%] Building CXX object cuneiform_src/cli/CMakeFiles/cuneiform-cli.dir/cuneiform-cli.cpp.o
In file included from /usr/include/ImageMagick-6/Magick++/Include.h:13:0,
from /usr/include/ImageMagick-6/Magick++.h:9,
from /tmp/cuneiform-linux-1.1.0/cuneiform_src/cli/cuneiform-cli.cpp:156:
/usr/include/ImageMagick-6/magick/magick-config.h:21:38: fatal error: magick/magick-baseconfig.h: No such file or directory
#include “magick/magick-baseconfig.h”
^
compilation terminated.
通过搜索标头,发现它可以在不同的 ImageMagick 目录中找到:
$ find /usr/include/ -name "*baseconfig*"
/usr/include/x86_64-linux-gnu/ImageMagick-6/magick/magick-baseconfig.h7
软链接丢失的文件并没有解决问题。
解决办法:参考http://bazaar.launchpad.net/~jpakkane/cuneiform-linux/trunk/files
cuneiform_src/ 中的文件的时间戳 = 2010 或更早。难怪找不到新的 Debian 路径。(未找到 magick/magick-baseconfig.h)。
简单修复:
mkdir /usr/local/include/magick
cp /usr/include/x86_64-linux-gnu/ImageMagick-6/magick/magick-baseconfig.h /usr/local/include/magick/
#include
using namespace Magick;
int main(int argc, char ** argv)
{
InitializeMagick(*argv);
Image image("100x100", "white");
image.pixelColor(49, 49, "red");
image.write("red_pixel.jpeg");
return 0;
}
编译
g++ -O2 -o example.o example.cpp `Magick++-config --cppflags --cxxflags --ldflags --libs`
报错:
terminate called after throwing an instance of ‘Magick::Error Missing Delegate’ what(): img: no decode delegate for this image format `JPG’ @ error/constitute.c/ReadImage/746
terminate called after throwing an instance of
'Magick::ErrorMissingDelegate
类似的错误
问题原因:如果用convert xx.png xx.jpeg等指令也会报类似错误,原因是没有png及jpeg的库导致的。一些必要的依赖没有安装,必须根据此说明重新安装带有所有附加组件的 ImageMagick
sudo apt-get update
sudo apt-get install build-essential
sudo apt-get install libpng12-0 libpng12-dev
sudo apt-get install libjpeg62 libjpeg62-dev
sudo apt-get install -y libtiff-dev
然后重新编译安装
重新安装办法快速见:
#These are the steps required in order to Install ImageMagick with JPG, PNG and TIFF delegates.
sudo apt-get update
#Install Build-Essential in order to configure and make the final Install
sudo apt-get install build-essential
#libjpg62-dev required in order to work with basic JPG files
sudo apt-get install -y libjpeg62-dev
#libtiff-dev is required in order to work with TIFF file format
sudo apt-get install -y libtiff-dev
#Download ImageMagick
wget https://www.imagemagick.org/download/ImageMagick.tar.gz
#Untar Imagemagick
tar xvzf ImageMagick.tar.gz
#Access the working directory
cd ImageMagick/[version_number]
#Configure and make sure to disable the "shared" option
./configure --disable-shared
#Make
sudo make
#Install
sudo make install
#Final Check
sudo make check