http://467754239.blog.51cto.com/4878013/1602518/

一、功能概述

ImageMagick是第三方的图片处理软件,功能要比GD强大。建议两者都安装,并不冲突。

imagick是php的一个扩展模块,它调用ImageMagick提供的API来进行图片的操作。

Ghostscript是一套建基于Adobe、PostScript及可移植文档格式(PDF)的页面描述语言等而编译成的免费软件。
Ghostscript最初是以商业软件形式在PC市场上发售,并称之为“GoScript”。但由于速度太慢(半小时一版A4),销量极差。后来有心人买下了版权,并改在Linux上开发,成为了今日的Ghostscript。
已经从Linux版本移植到其他操作系统,如其他Unix、Mac OS X、VMS、Windows、OS/2和Mac OS classic。

ImageMagick无法直接实现pdf文档到图片的转换,需要借助于gostscript软件包

二、安装方式

1、编译安装ImageMagick

1
2
3
4
5
6
# tar xf ImageMagick-6.8.9-9.tar.gz
# cd ImageMagick-6.8.9-9
# ./configure --prefix=/usr/local/imagemagick
# make && make install
 
编译安装完成之后记得配置./convert的环境变量

2、编译安装imagick

1
2
3
4
5
# tar -xf imagick-3.2.0RC1.tgz
# cd imagick-3.2.0RC1
# /usr/local/php/bin/phpize
# ./configure --with-php-config=/usr/local/php/bin/php-config --with-imagick=/usr/local/imagemagick
# make && make install

3、编译安装Ghostscript

1
2
3
4
5
6
7
# tar xf ghostscript-9.02.tar.gz
# cd ghostscript-9.02
# ./configure
# make && make install
 
建议Ghostscript使用yum安装,因为安装的时候有一些字体库依赖包
# yum -y install ghostscrip

三、php加载imagick模块

1、php加载imagick动态模块

1
2
# echo 'extension="imagick.so"' >> /usr/locla/php/etc/php.ini
# service php-fpm restart

2、查看phpinfo页面

四、ImageMagick命令行的使用

注释:仅安装ImageMagick为安装GhostScript的效果

手动使用命令实现图片到图片、图片到pdf等等的转换;但是却无法实现pdf到图片的转换,命令如下:

1
2
3
4
5
6
7
8
9
[root@localhost opt]# ls
document.pdf  imagice.png
[root@localhost opt]# /usr/local/imagemagick/bin/convert imagice.png nihao_tupian.jpg
[root@localhost opt]# ls
document.pdf  imagice.png  nihao_tupian.jpg
[root@localhost opt]# /usr/local/imagemagick/bin/convert document.pdf nihao_wendang.pdf
convert: no images defined `nihao_wendang.pdf' @ error/convert.c/ConvertImageCommand/3210.
[root@localhost opt]# ls
document.pdf  imagice.png  nihao_tupian.jpg

安装GhostScript后的效果

1
2
3
4
5
6
7
8
[root@localhost opt]# /usr/local/imagemagick/bin/convert document.pdf nihao_wendang.pdf
convert: no images defined `nihao_wendang.pdf' @ error/convert.c/ConvertImageCommand/3210
 
[root@localhost opt]# yum -y install ghostscript
 
[root@localhost opt]# /usr/local/imagemagick/bin/convert document.pdf nihao_wendang.pdf
[root@localhost opt]# ls
document.pdf  imagice.png  nihao_tupian.jpg  nihao_wendang.pdf

五、php程序之调用

1、php程序调用imagick程序

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
        $pdfFile=$_GET['pdf'];
        if(empty($pdfFile)){
            $path='/www/111111.pdf';
                var_dump(is_readable($path));
            $pdfFile='111111.pdf';
        }else{
            $path='/www/yanjiuyuan/pdf/'.$pdfFile;
        }
        if(!file_exists($path)){
                echo "no";
        }
 
        $Return=array();
        $filelen=strlen($pdfFile);
        $strFileName=substr($pdfFile,0,$filelen-4);
        $fp = @fopen ( "./pdf/".$strFileName.".txt"'r' );
        if ($fp) {
           $arr = unserialize ( fgets ( $fp ) );
           $Return=$arr;
           fclose ( $fp );
        }else{
            $IM = new imagick();
            $IM->setResolution(150,150);
            $IM->setCompressionQuality(180);
            $IM->readImage($path);
            foreach ($IM as $Key => $Var) {
                $Var->setImageFormat('png');
                $Filename = '/www/yanjiuyuan/pdf/' time() . uniqid() . '.png';
                if ($Var->writeImage($Filename) == true) {
                   // $Return[] = $Filename;
                    array_push($Return,$Filename);
                }
            }
            $fp = fopen ("/www/yanjiuyuan/pdf/".$strFileName.".txt"'w' );
            fwrite ( $fp, serialize ( $Return ) );
            fclose ( $fp );
        }
        $imageHtml=array();
        foreach($Return as $key=>$value){
            $strNumber=strlen($value);
            $imPath=substr($value,$strNumber-27,$strNumber);
            $url='www/yanjiuyuan/pdf/'.$imPath;
            $imageHtml[]=$url;
        }
       print_r($imageHtml);
    ?>

2、页面访问url

3、查看生成的图片

本文出自 “郑彦生” 博客,请务必保留此出处http://467754239.blog.51cto.com/4878013/1602518

ImageMagick、imagick和ghostscript三者的关联的更多相关文章

  1. imagemagick imagick

    imagemagick#图像处理软件 安装解压 ./configure make make install imagick#是php图像扩展模块 调用imagemagick处理图像 安装解压/opt/ ...

  2. linux /proc/sys/fs/file-nr /proc/sys/fs/file-max /etc/security/limits.conf 三者的关联

    ulimit -n 对应 /etc/security/limits.conf 文件设置 问题: Can’t open so many files 对于linux运维的同学们,相信都遇到过这个问题. 在 ...

  3. Centos 安装ImageMagick 与 imagick for php步骤详解

    现在有很多朋友在使用安装ImageMagick imagick for php了,今天自己也想做但是不知道如何操作,下面我来给大家介绍Centos 安装ImageMagick imagick for ...

  4. php imagemagick 翻译目录

    图像处理(ImageMagick) 介绍 安装/配置 要求 安装 运行时配置 资源类型 预定义常数 例子 基本用法 Imagick - Imagick课 Imagick :: adaptiveBlur ...

  5. backbone实例01

    backbonejs往简单说,就是一前端MVC框架,适合用于单页面.复杂的前端逻辑. 直接上代码,里面都有相关注释,重点是理解清楚view.collection.model这三者如何关联调用. < ...

  6. Java魔法堂:URI、URL(含URL Protocol Handler)和URN

    一.前言 过去一直搞不清什么是URI什么是URL,现在是时候好好弄清楚它们了!本文作为学习笔记,以便日后查询,若有纰漏请大家指正! 二.从URI说起    1. 概念 URI(Uniform Reso ...

  7. c++模板库(简介)

    目 录 STL 简介 ......................................................................................... ...

  8. Java中的TreeMap、Comparable、Comparator

    我们知道HashMap的存储位置是按照key这个对象的hashCode来存放的,而TreeMap则是不是按照hashCode来存放,他是按照实现的Comparable接口的compareTo这个方法来 ...

  9. [platform]linux platform device/driver(一)--Driver是如何找到对应的device

    1.platform device是怎么"自动"关联到platform driver上的? 转向linux driver有些时间了,前段时间碰到个问题,在Linux kernel ...

随机推荐

  1. 1.Linux进程--进程标识号

    函数原型 pid_t fork(void); fork的奇异之处在于它被调用一次,却返回两次,它可能有三种不同的返回值: 1.在父进程中.fork返回新创建的子进程的PID 2.在子进程中,fork返 ...

  2. 奇怪吸引子---LorenaMod2

    奇怪吸引子是混沌学的重要组成理论,用于演化过程的终极状态,具有如下特征:终极性.稳定性.吸引性.吸引子是一个数学概念,描写运动的收敛类型.它是指这样的一个集合,当时间趋于无穷大时,在任何一个有界集上出 ...

  3. Revit中如何给不同构件着色

    在Revit构件密集,默认的显示模式难以区分不同构件的区别,比如建筑立面有很多不同的机电管道,风管.水管,电缆桥架等,可一个给不同的机电管线添加不同的颜色,以示其区别,如下图所示,完成着色后,各种不同 ...

  4. angularjs图片上传和预览 - ng-file-upload

    ng-file-upload ajax上传文件 官方demo地址 安装 bower install ng-file-upload-shim --save(for non html5 suppport) ...

  5. 使用quicklz缩小程序体积

    目录 简述 压缩和解压代码 压缩代码 解压代码 将二进制文件生成C数组程序代码 简述 有一个需求是这样的,写的一个程序内置了一个很大的文件(实际就是抓取epsg.io的内容里面的epsg.io.jso ...

  6. phpBB3.2 自动检测浏览器语言

    这是根据HTTP request header里的Accept-Language信息来处理的. 首先看一下Accept-Language的格式 Accept-Language: <languag ...

  7. MUI中等待框的H5实现

    MUI没有内置的那个弹出转圈圈的那个等待框,那个nativeui.showwaiting是只能用于app中的,不能用在H5网页中的,网上找了下,找到个别人已经写好的,自己 测试了下没问题,先记下来 @ ...

  8. 译: 6. RabbitMQ Spring AMQP 之 RPC

    Remote procedure call (RPC) 在第二篇教程中,我们学习了如何使用工作队列在多个工作人员之间分配耗时的任务. 但是如果我们需要在远程计算机上运行一个函数并等待结果呢?嗯,这是一 ...

  9. 物联网架构成长之路(9)-双机热备Keepalived了解

    1. 前言 负载均衡LB,高可用HA,这一小结主要讲双机热备方案保证高可用.这里选择Keepalived作为双机热备方案,下面就对具体的配置进行了解.2. 下载Keepalived wget http ...

  10. ⑤NuPlayer播放框架之GenericSource源码分析

    [时间:2017-01] [状态:Open] [关键词:android,nuplayer,开源播放器,播放框架,GenericSource] 0 导读 GenericSource是NuPlayer:: ...