pdf转成图片 php

前提,我是linux环境

首先,安装imagick(一个PHP的扩展),用ImageMagick提供的API来进行图片的创建与修改,不过这些操作已经包装到扩展imagick中去了,最终调用的是ImageMagick提供的API。所以要先安装ImageMagick依赖,同时也要安装ghostscript   yum install ghostscript

 

第一步【安装ghostscript】

[root@haiyan application]# yum install ghostscript
已加载插件:fastestmirror
设置安装进程
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository epel is listed more than once in the configuration
Loading mirror speeds from cached hostfile
* base: mirrors.cloud.aliyuncs.com
* epel: mirrors.cloud.aliyuncs.com
* extras: mirrors.cloud.aliyuncs.com
* updates: mirrors.cloud.aliyuncs.com
base | 3.7 kB 00:00
epel | 4.3 kB 00:00
extras | 3.4 kB 00:00
gitlab_gitlab-ce/signature | 836 B 00:00
gitlab_gitlab-ce/signature | 1.0 kB 00:00 ...
gitlab_gitlab-ce-source/signature | 836 B 00:00
gitlab_gitlab-ce-source/signature | 951 B 00:00 ...
updates | 3.4 kB 00:00
解决依赖关系
--> 执行事务检查
---> Package ghostscript.x86_64 0:8.70-21.el6_8.1 will be 安装
--> 处理依赖关系 urw-fonts >= 1.1,它被软件包 ghostscript-8.70-21.el6_8.1.x86_64 需要
--> 处理依赖关系 ghostscript-fonts,它被软件包 ghostscript-8.70-21.el6_8.1.x86_64 需要
--> 执行事务检查
---> Package ghostscript-fonts.noarch 0:5.50-23.2.el6 will be 安装
--> 处理依赖关系 xorg-x11-font-utils,它被软件包 ghostscript-fonts-5.50-23.2.el6.noarch 需要
---> Package urw-fonts.noarch 0:2.4-11.el6 will be 安装
--> 执行事务检查
---> Package xorg-x11-font-utils.x86_64 1:7.2-11.el6 will be 安装
--> 处理依赖关系 libfontenc.so.1()(64bit),它被软件包 1:xorg-x11-font-utils-7.2-11.el6.x86_64 需要
--> 处理依赖关系 libXfont.so.1()(64bit),它被软件包 1:xorg-x11-font-utils-7.2-11.el6.x86_64 需要
--> 执行事务检查
---> Package libXfont.x86_64 0:1.5.1-2.el6 will be 安装
---> Package libfontenc.x86_64 0:1.1.2-3.el6 will be 安装
--> 完成依赖关系计算

 

依赖关系解决

 

================================================================================
软件包 架构 版本 仓库 大小
================================================================================
正在安装:
ghostscript x86_64 8.70-21.el6_8.1 updates 4.4 M
为依赖而安装:
ghostscript-fonts noarch 5.50-23.2.el6 base 590 k
libXfont x86_64 1.5.1-2.el6 base 145 k
libfontenc x86_64 1.1.2-3.el6 base 29 k
urw-fonts noarch 2.4-11.el6 base 3.1 M
xorg-x11-font-utils x86_64 1:7.2-11.el6 base 75 k

 

事务概要
================================================================================
Install 6 Package(s)

 

总下载量:8.3 M
Installed size: 26 M
确定吗?[y/N]:y
下载软件包:
(1/6): ghostscript-8.70-21.el6_8.1.x86_64.rpm | 4.4 MB 00:01
(2/6): ghostscript-fonts-5.50-23.2.el6.noarch.rpm | 590 kB 00:00
(3/6): libXfont-1.5.1-2.el6.x86_64.rpm | 145 kB 00:00
(4/6): libfontenc-1.1.2-3.el6.x86_64.rpm | 29 kB 00:00
(5/6): urw-fonts-2.4-11.el6.noarch.rpm | 3.1 MB 00:00
(6/6): xorg-x11-font-utils-7.2-11.el6.x86_64.rpm | 75 kB 00:00
--------------------------------------------------------------------------------
总计 4.9 MB/s | 8.3 MB 00:01
运行 rpm_check_debug
执行事务测试
事务测试成功
执行事务
正在安装 : libfontenc-1.1.2-3.el6.x86_64 1/6
正在安装 : libXfont-1.5.1-2.el6.x86_64 2/6
正在安装 : 1:xorg-x11-font-utils-7.2-11.el6.x86_64 3/6
正在安装 : urw-fonts-2.4-11.el6.noarch 4/6
正在安装 : ghostscript-fonts-5.50-23.2.el6.noarch 5/6
正在安装 : ghostscript-8.70-21.el6_8.1.x86_64 6/6
Verifying : ghostscript-8.70-21.el6_8.1.x86_64 1/6
Verifying : 1:xorg-x11-font-utils-7.2-11.el6.x86_64 2/6
Verifying : libfontenc-1.1.2-3.el6.x86_64 3/6
Verifying : libXfont-1.5.1-2.el6.x86_64 4/6
Verifying : urw-fonts-2.4-11.el6.noarch 5/6
Verifying : ghostscript-fonts-5.50-23.2.el6.noarch 6/6

 

已安装:
ghostscript.x86_64 0:8.70-21.el6_8.1

 

作为依赖被安装:
ghostscript-fonts.noarch 0:5.50-23.2.el6 libXfont.x86_64 0:1.5.1-2.el6
libfontenc.x86_64 0:1.1.2-3.el6 urw-fonts.noarch 0:2.4-11.el6
xorg-x11-font-utils.x86_64 1:7.2-11.el6

 

完毕!

第二步【安装ImageMagick 】

 

 

 

tar -zxvf ImageMagick.tar.gz

 

[root@haiyan bin]# pwd
/application/imagemagick/bin
[root@haiyan bin]# vi /etc/profile
[root@haiyan bin]# source /etc/profile
[root@haiyan bin]# cd ../
[root@haiyan imagemagick]# magick
magick magick-script

 

PATH=/application/mysql/bin:/application/jdk/bin:/application/jdk/jre/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

export PATH=/application/mysql/bin:$PATH

export PATH=/application/imagemagick/bin:$PATH

 

 

[root@haiyan imagick-3.4.1]# /application/php/bin/phpize
Configuring for:
PHP Api Version: 20121113
Zend Module Api No: 20121212
Zend Extension Api No: 220121212

 

 

 

[root@haiyan imagick-3.4.1]# echo $PATH
/application/imagemagick/bin:/application/mysql/bin:/application/mysql/bin:/application/jdk/bin:/application/jdk/jre/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

 

[root@haiyan imagick-3.4.1]# ./configure --with-php-config=/application/php/bin/php-config --with-imagick=/application/imagemagick

 

[root@haiyan imagick-3.4.1]# make

creating libtool
appending configuration tag "CXX" to libtool
configure: creating ./config.status
config.status: creating config.h

[root@haiyan imagick-3.4.1]# make install
Installing shared extensions: /application/php-5.5.32/lib/php/extensions/no-debug-non-zts-20121212/
Installing header files: /application/php-5.5.32/include/php/
[root@haiyan imagick-3.4.1]# cd /application/php-5.5.32/lib/php/extensions/no-debug-non-zts-20121212/
[root@haiyan no-debug-non-zts-20121212]# ll
总用量 1176
-rwxr-xr-x 1 root root 1200048 3月 2 17:06 imagick.so

 

 

 

查找php文件名的文件

[root@haiyan etc]# ll php*
-rw-r--r-- 1 root root 2751 3月 2 16:11 php.ini

[root@haiyan bin]# ./php -v

PHP 5.5.32 (cli) (built: Feb 28 2017 14:10:48)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies

 

ps aux | grep php

 

 

编辑php.ini 将扩展打开

[root@haiyan lib]# vi php.ini 

[imagick]

extension = imagick.so

 

 

 查看扩展是否安装成功

[root@haiyan php]# ./bin/php -m
[PHP Modules]
bcmath
Core
ctype
curl
date
dom
ereg
fileinfo
filter
ftp
gd
hash
iconv
imagick
json
libxml
mbstring
mcrypt
mhash
mysql
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
sqlite3
standard
sysvsem
tokenizer
xml
xmlreader
xmlrpc
xmlwriter
xsl
zlib

[Zend Modules]

 

posted @ 2017-03-02 18:07  乐公子  阅读(462)  评论(0编辑  收藏  举报