Use PHP and ImageMagick to process image file upload and zoom processing (paste)

Source: Internet
Author: User
Tags format copy file upload imagemagick php and
Upload and zoom processing of image files using PHP and ImageMagick
PHP processing file Upload is very simple, but if you want to upload the image zoom processing, although it can be done with GD, but
To carry out the more cumbersome processing. ImageMagick is an image processing package, which is common in Linux software packages. It contains the Xu
Multi-processing Image tool, it can be transformed into image file format can also be a variety of image processing, where we will use its
Image scaling feature. This is implemented through the tool convert in its package so that you can invoke the
Convert-geometry width x Gao yuan file scaled file

Please create a images directory under the current directory and make the Web executable user writable, which is used to store uploaded pictures and

The scaled picture.
Below is a simple small example, including image upload and processing, tested under redhat6.0+php3.0.12.

uploadform.html: File Upload Form

〈html>
〈head>
〈title> Select File 〈/title>
〈/head>
〈body align= "CENTER" >
〈form enctype= "Multipart/form-data" action= "Upload.php3" method=post>
Select Picture file: 〈input name= "image" type= "file" >
〈input type= "Submit" value= "Send File" >
〈/form>
〈/body>
〈/html>


UPLOAD.PHP3: Processing the uploaded image file

〈html>
〈head>
〈title> processing 〈/title>
〈/head>
〈body>
〈?
$flag = "true";
if (Isset ($image) && $image &&
($image _type = "Image/gif" | | $image _type = "Image/png"
|| $image _type = "Image/pjpeg")) {//To determine the format of uploaded files, etc.
$dest _image = "./images/". $image _name;
if (@copy ($image, $dest _image)) {//copy upload file to images directory

$small _image = "./images/small". $image _name;
$exec _str = "/usr/bin/x11/convert-geometry 100x100". $dest _image. " ". $small _image;
@exec ($exec _str); Zoom on the image
}else
$flag = "false";

}else{


$flag = "false";
}

if ($flag = = "false") {
echo "Error〈p>";
echo "〈a href=\" uploadform.html\ "> re-upload 〈/a>";
}else{
echo "〈image src=\" $small _image\ ">";
echo "〈image src=\"./images/$image _name\ ">";
}
?>
〈/body>
〈/html>

If you combine the getimagesize function, we can also control the size of the scale. The database can be indexed or stored in the image file.
ImageMagick function is very powerful, not only can the picture file scaling, but also to flip, format conversion and so on.
Readers can refer to ImageMagick's Help file themselves.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.