GraphicsMagick安装—学习笔记

本文介绍GraphicsMagick的安装步骤及验证方法,并详细记录了编译安装Python接口pgmagick的过程,包括所需的依赖库boost的安装。

概述

GraphicsMagick是一个短小精悍的图片处理工具和库集合。用来处理图像的读取、写入和操作,支持超过88中图像格式,包括重要的DPX、GIF、JPEG、JPEG-2000、PNG、PDF、PNM和TIFF。

安装

tar -jxvf GraphicsMagick-1.3.32.tar.bz2
  • 编译
cd GraphicsMagick-1.3.32
bash ./configure --prefix=~/.local --enable-shared=true
make
make install
  • 验证是否安装成功
gm version
#输出
GraphicsMagick 1.3.32 2019-06-15 Q8 http://www.GraphicsMagick.org/
Copyright (C) 2002-2019 GraphicsMagick Group.
Additional copyrights and licenses apply to this software.
See http://www.GraphicsMagick.org/www/Copyright.html for details.

Feature Support:
  Native Thread Safe       yes
  Large Files (> 32 bit)   yes
  Large Memory (> 32 bit)  yes
  BZIP                     no
  DPS                      no
  FlashPix                 no
  FreeType                 yes
  Ghostscript (Library)    no
  JBIG                     yes
  JPEG-2000                yes
  JPEG                     yes
  Little CMS               no
  Loadable Modules         no
  Solaris mtmalloc         no
  OpenMP                   yes (201307 "4.0")
  PNG                      yes
  TIFF                     yes
  TRIO                     no
  Solaris umem             no
  WebP                     no
  WMF                      no
  X11                      yes
  XML                      no
  ZLIB                     yes

Host type: x86_64-pc-linux-gnu

Configured using the command:
  ./configure  '--prefix=~/.local' '--enable-shared=true'

Final Build Parameters:
  CC       = gcc
  CFLAGS   = -fopenmp -g -O2 -Wall -pthread
  CPPFLAGS = -I/usr/include/freetype2
  CXX      = g++
  CXXFLAGS = -pthread
  LDFLAGS  =
  LIBS     = -ljbig -ltiff -lfreetype -ljasper -ljpeg -lpng12 -lXext -lSM -lICE                                                                     -lX11 -llzma -lz -lm -lpthread

编译Python接口(pgmagick)

#~需具体用户目录
python3 setup.py install --prefix=~/.local
#非root用户没安装成功,使用root用户安装成功了
apt-get install python3-pgmagick

boost安装(pgmagick需要的依赖库)

tar -jxvf boost_1_70_0.tar.bz2
  • 指定目录安装
#~替换为绝对路径
cd boost_1_70_0
./bootstrap.sh --with-python=/usr/bin/python3 --with-python-version=3.5 --with-python-root=/usr/local/lib/python3.5 --prefix=~/.local
  • 修改project-config.jam文件
    在这里插入图片描述
  • 编译执行
#~替换为绝对路径
./b2   --with-python include=/usr/include/python3.5m --prefix=~/.local
./b2 install  --with-python include=/usr/include/python3.5m --prefix=~/.local
  • 指定安装目录会生成相应的文件
libboost_python35.a
libboost_python35.so
libboost_python35.so.1
libboost_python35.so.1.70
libboost_python35.so.1.70.0

参考资料

GraphicsMagick百度
GraphicsMagick官网
如何从官网下载GraphicsMagick(Linux版本安装包)
ubuntu 非root用户安装GraphicsMagick,以及其python接口pgmagick
非root用户安装Python 三方模块
boost python3依赖安装
Boost Python 的安装配置以及示例 (支持python3.x)

### Linux 系统安装 GraphicsMagick #### 安装依赖库 在开始安装之前,确保系统中已经安装了必要的开发库和工具。对于基于 Red Hat 的系统(如 CentOS),可以使用以下命令安装所需的依赖: ```bash yum install -y gcc make libpng-devel libjpeg-devel libtiff-devel jasper-devel freetype-devel libtool-ltdl-devel ``` 对于基于 Debian 的系统(如 Ubuntu),可以使用以下命令: ```bash apt-get update apt-get install -y build-essential libpng-dev libjpeg-dev libtiff-dev libjasper-dev libfreetype6-dev libtool ``` #### 下载并解压 GraphicsMagick 源码包 接下来,下载 GraphicsMagick 的源代码包,并解压到当前目录: ```bash curl -o GraphicsMagick-1.3.36.tar.gz https://jaist.dl.sourceforge.net/project/graphicsmagick/graphicsmagick/1.3.36/GraphicsMagick-1.3.36.tar.gz tar -zxvf GraphicsMagick-1.3.36.tar.gz cd GraphicsMagick-1.3.36/ ``` #### 配置安装选项 进入解压后的目录后,使用 `./configure` 命令来配置安装选项。这里以 `/app/GraphicsMagick-x` 作为安装路径为例: ```bash ./configure --prefix=/app/GraphicsMagick-x ``` 如果需要更详细的配置选项,可以指定更多的参数,例如: ```bash ./configure \ --prefix=/usr/local/GraphicsMagick-1.3.22 \ --exec-prefix=/usr/local/GraphicsMagick-1.3.22 \ --bindir=/usr/local/GraphicsMagick-1.3.22/bin \ --sbindir=/usr/local/GraphicsMagick-1.3.22/sbin \ --sysconfdir=/usr/local/GraphicsMagick-1.3.22/etc \ --datadir=/usr/local/GraphicsMagick-1.3.22/share \ --includedir=/usr/local/GraphicsMagick-1.3.22/include \ --libdir=/usr/local/GraphicsMagick-1.3.22/lib \ --libexecdir=/usr/local/GraphicsMagick-1.3.22/libexec \ --localstatedir=/usr/local/GraphicsMagick-1.3.22/var \ --sharedstatedir=/usr/local/GraphicsMagick-1.3.22/share/com \ --mandir=/usr/local/GraphicsMagick-1.3.22/share/man \ --infodir=/usr/local/GraphicsMagick-1.3.22/share/info \ --enable-libtool-verbose \ --with-included-ltdl \ --enable-shared \ --disable-static \ --with-modules \ --with-frozenpaths \ --without-perl \ --without-magick-plus-plus \ --with-quantum-depth=8 \ --enable-symbol-prefix ``` #### 编译并安装 配置完成后,使用 `make` 和 `make install` 命令进行编译和安装: ```bash make && make install ``` #### 配置环境变量 为了能够在任何地方调用 GraphicsMagick 的命令,需要将安装路径添加到系统的环境变量中。编辑 `/etc/profile` 文件,添加以下内容: ```bash export PATH=/app/GraphicsMagick-x/bin:$PATH ``` 保存文件后,使更改立即生效: ```bash source /etc/profile ``` ### Windows 系统安装 GraphicsMagick 对于 Windows 用户,可以直接从官方网站下载预编译的二进制文件。访问 [GraphicsMagick 官方网站](http://www.graphicsmagick.org/download.html),选择适合你系统的版本进行下载。 下载完成后,按照安装向导的提示完成安装过程。安装过程中可以选择自定义安装路径,并确保将 GraphicsMagick安装目录添加到系统环境变量中。 ### 测试安装 安装完成后,可以通过以下命令测试是否成功安装GraphicsMagick: ```bash gm convert -version ``` 如果输出显示了 GraphicsMagick 的版本信息,则表示安装成功。 ### 示例:图片缩放 使用 GraphicsMagick 进行图片缩放的操作非常简单。假设有一张名为 `test.png` 的图片,想要将其缩放到 50x50 像素,可以使用以下命令: ```bash gm convert /Users/user/Downloads/test.png -resize "50x50" resized_test.png ``` 这条命令会将 `test.png` 图片缩放到 50x50 像素,并将结果保存为 `resized_test.png`[^1]。 ### 相关问题 1. 如何在 Linux 系统上卸载 GraphicsMagick? 2. 在安装 GraphicsMagick 时遇到依赖问题怎么办? 3. 如何在 Windows 系统上配置 GraphicsMagick 的环境变量? 4. 使用 GraphicsMagick 进行图片处理时有哪些常用命令? 5. 如何验证 GraphicsMagick 是否正确安装
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值