search
Homephp教程php手册用php和imagemagick来处理图片文件的上传和缩放处理

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

Jun 13, 2016 am 10:28 AM
imagemagickphpuploadandpicturedeal withdocumentuseofZoom

用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; $exec_str = "/usr/bin/X11/convert -geometry 100x100 ".$dest_image." ".$small_image; @exec($exec_str); //进行图像的缩放 }else $flag = "false"; }else{ $flag = "false"; } if( $flag == "false"){ echo "error〈p>"; echo "〈a href=DownloadFilesa2004-11-05["uploadform.html[">重新上载〈/a>"; }else{ echo "〈image src=/DownloadFilesa2004-11-05["$small_image[">"; echo "〈image src=/DownloadFilesa2004-11-05\".images$image_name[">"; } ?> 〈/body> 〈/html> 如果结合GetImageSize函数,我们还可以控制缩放的大小。结合数据库可以对图片文件进行索引或者存储等。 ImageMagick的功能是很强大的,不仅能对图片文件进行缩放,还有进行翻转、格式转化等等功能。 读者可以自己参看ImageMagick的帮助文件。

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor