用php和imagemagick来处理图片文件的上传和缩放处理
Posted royal_coffee
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了用php和imagemagick来处理图片文件的上传和缩放处理相关的知识,希望对你有一定的参考价值。
php处理文件的上传是很简便的,但是如果要对上传的图片进行缩放处理的话,虽说能用GD来做,但是
要进行比较繁琐的处理。ImageMagick是一个图像处理包,一般的Linux/'>Linux软件包中都会有的。它包含了许
多处理图像的工具,它可以进行图像文件格式的转化还可以对图像进行各种处理,其中我们将用到它的
图像缩放功能。这个通过它的软件包中的工具convert来实现,这样来调用
convert -geometry 宽x高 源文件 缩放后的文件
请在当前目录下建立一个images的目录,并且能让web执行用户可写,这个目录用来存放上载后的图片和缩放的图片。
底下是一个简单小例子,包括图片上传和处理,在RedHat6.0+php3.0.12下测试通过。
uploadform.html:文件上传表单
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
upload.php3:处理上传后的图片文件
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
![](https://image.cha138.com/20210516/20c90c80543a4bf5b38a1bf2f65e12f2.jpg)
如果结合GetImageSize函数,我们还可以控制缩放的大小。结合数据库可以对图片文件进行索引或者存储等。
ImageMagick的功能是很强大的,不仅能对图片文件进行缩放,还有进行翻转、格式转化等等功能。
读者可以自己参看ImageMagick的帮助文件。
以上是关于用php和imagemagick来处理图片文件的上传和缩放处理的主要内容,如果未能解决你的问题,请参考以下文章
Linux端图形处理工具ImageMagick在Centos上的安装
php安装imagemagick扩展 常见问题与解决方案(win平台)