Home  >  Article  >  php教程  >  用php和imagemagick来处理图片文件的上传和缩放处理(转贴)

用php和imagemagick来处理图片文件的上传和缩放处理(转贴)

WBOY
WBOYOriginal
2016-06-13 11:19:55975browse

用php和imagemagick来处理图片文件的上传和缩放处理
php处理文件的上传是很简便的,但是如果要对上传的图片进行缩放处理的话,虽说能用GD来做,但是
要进行比较繁琐的处理。ImageMagick是一个图像处理包,一般的Linux软件包中都会有的。它包含了许
多处理图像的工具,它可以进行图像文件格式的转化还可以对图像进行各种处理,其中我们将用到它的
图像缩放功能。这个通过它的软件包中的工具convert来实现,这样来调用
        convert -geometry 宽x高 源文件 缩放后的文件
        
请在当前目录下建立一个images的目录,并且能让web执行用户可写,这个目录用来存放上载后的图片和
缩放的图片。
底下是一个简单小例子,包括图片上传和处理,在RedHat6.0+php3.0.12下测试通过。
uploadform.html:文件上传表单
〈HTML>
〈HEAD>
〈TITLE>选择文件〈/TITLE>
〈/HEAD>
〈BODY ALIGN="CENTER">
〈FORM ENCTYPE="multipart/form-data" ACTION="upload.php3" METHOD=POST>
选择图片文件: 〈INPUT NAME="image" TYPE="file">
〈INPUT TYPE="submit" VALUE="Send File">
〈/FORM>
〈/BODY>
〈/HTML>
upload.php3:处理上传后的图片文件
〈html>
〈head>
〈title>处理〈/title>
〈/head>
〈body>
〈?
$flag = "true";
if(isset($image) && $image &&
        ($image_type = "image/gif" || $image_type = "image/png"
           || $image_type = "image/pjpeg")){    //判断上载文件的格式等
        $dest_image = "./images/".$image_name;
        if(@copy($image,$dest_image)){    //拷贝上载文件到images目录下
        $small_image = "./images/small".$image_name;

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn