Php and imagemagick are used to process the upload and zoom (posting) of image files)

Source: Internet
Author: User
Tags imagemagick
It is easy to use php and imagemagick to process the upload and scaling of image files. However, if you want to scale the uploaded image, you can use GD, however, it is complicated. ImageMagick is an image processing package, which is available in common Linux software packages. It contains many image processing tools and uses php and imagemagick to process image file upload and scaling.
Php is very easy to process file uploads. However, if you want to scale the uploaded image, you can use GD,
Complicated processing is required. ImageMagick is an image processing package, which is available in common Linux software packages. It contains
The multi-processing image tool can convert the image file format and perform various processing on the image.
Image scaling function. This is implemented through convert, a tool in its software package, so as to call
Convert-geometry width x High source file scaled file

Create an images directory in the current directory and enable users to write images on the web. this directory is used to store uploaded images and

The scaled image.
Below is a simple example, including image upload and processing. the test passes in RedHat6.0 + php3.0.12.

Uploadform.html: file upload form

<HTML>
<HEAD>
<TITLE> select a file </TITLE>
</HEAD>
<Body align = "CENTER">
<Form enctype = "multipart/form-data" ACTION = "upload. php3" METHOD = POST>
Select an image file: <input name = "image" TYPE = "file">
<Input type = "submit" VALUE = "Send File">
</FORM>
</BODY>
</HTML>


Upload. php3: process uploaded image files

<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") {// you can specify the format of the uploaded file.
$ Dest_image = "./images/". $ image_name;
If (@ copy ($ image, $ dest_image) {// copy the uploaded file to the images Directory

$ Small_image = "./images/small". $ image_name;
$ Exec_str = "/usr/bin/X11/convert-geometry 100x100". $ dest_image. "". $ small_image;
@ Exec ($ exec_str); // scale the image
} Else
$ Flag = "false ";

} Else {


$ Flag = "false ";
}

If ($ flag = "false "){
Echo "error <p> ";
Echo "<a href = \" uploadform.html \ "> upload again </a> ";
} Else {
Echo "<image src = \" $ small_image \ "> ";
Echo "<image src = \"./images/$ image_name \ "> ";
}
?>
</Body>
</Html>

If we use the GetImageSize function, we can also control the scaling size. In combination with databases, you can index or store image files.
ImageMagick is very powerful. it not only Scales image files, but also performs flip, format conversion, and other functions.
Readers can refer to the ImageMagick help file by themselves.

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.