用php和imagemagick来处理图片文件的上传和缩放处理(转贴)
用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;

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

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.

Notepad++7.3.1
Easy-to-use and free code editor

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
