PHP image Modification

Source: Internet
Author: User
This article is about the effect of modifying images. I mainly used functions in the GD library in php. I didn't expect php to have this brutal capability, which was unexpected. First look at the code upload_image.php, mainly an upload control, used to select the image htmlheadtitletitlestyletypetextcssstyleheadbodyformaction

This article is about the effect of modifying images. I mainly used functions in the GD library in php. I didn't expect php to have this brutal capability, which was unexpected. First look at the code upload_image.php, mainly an upload control, used to select the image html head title/title style type = "text/css"/style/head body form action ="

This article is about the effect of modifying images. I mainly used functions in the GD library in php. I didn't expect php to have this brutal capability, which was unexpected.

First look at the code upload_image.php, mainly an upload control, used to select an image

                                    
             
  
Your username
Upload image*
* Acceptable image formats include: GIF, JPG/JPEG and PNG.
Image Caption

Then the logic for uploading and processing images is check_image.php.

                         Here is your pic!                Your image has been saved! $ _ POST ['id'];?>. Jpg "alt =" "/>    
                         Here is your pic!                So how does it feel to be famous?

Here is the picture you just uploaded to your servers:

$ Imagename;?> "Style =" float: left; "alt =" "/>
Image save:
Height:
Widht:
Upload date:

You may apply a special effect to your image from the list of option below. Note: saving an image with any of the filters appliedCan be undone

Finally, it is a preview page image_appst.php.

 

The second image_check.php is messy. on this page, you can upload, process, and preview images. Note the following section.

    
     $imagename;?>" style="float:left;" alt="" />

If the image is uploaded and accessed directly, if the image is previewed, the image is read from image_effect.php. Here, the image is read from the memory and displayed based on the selected processing effect. As follows:

switch($effect){    case IMG_FILTER_NEGATE:        imagefilter($image , IMG_FILTER_NEGATE);    break;    case IMG_FILTER_GRAYSCALE:        imagefilter($image , IMG_FILTER_GRAYSCALE);    break;        case IMG_FILTER_EMBOSS:        imagefilter($image , IMG_FILTER_EMBOSS);    break;        case IMG_FILTER_GAUSSIAN_BLUR:        imagefilter($image , IMG_FILTER_GAUSSIAN_BLUR);    break;    }

After the image filter method is used to process the image, the image will be output to the page. Note that the second parameter of the imagejpeg method is a null string so that it will not be written to the hard disk, if the second parameter is set to overwrite the original image, you can preview the image as needed before saving the image, as shown below:

header('Content-Type:image/jpeg');imagejpeg($image , '' , 100);

Similar methods are called in check_image.php, but the second parameter is specified here to save the image:

imagejpeg($image , $dir.'/'.$_POST['id'].'.jpg' , 100);

Note: Here we only write three processing results. This is only part of all enumeration. Let's look at all the processing methods:

IMG_FILTER_NEGATE: reverses all colors in the image.
IMG_FILTER_GRAYSCALE: converts an image to a grayscale image.
IMG_FILTER_BRIGHTNESS: changes the brightness of an image. Use arg1 to set the brightness level.
IMG_FILTER_CONTRAST: changes the image contrast. Use arg1 to set the contrast level.
IMG_FILTER_COLORIZE: similar to IMG_FILTER_GRAYSCALE, but color can be specified. Use arg1, arg2, and arg3 to specify red, blue, and green respectively. The range of each color is 0 to 255.
IMG_FILTER_EDGEDETECT: Uses edge detection to highlight the image edge.
IMG_FILTER_EMBOSS: embossed the image.
IMG_FILTER_GAUSSIAN_BLUR: blur an image using Gaussian algorithm.
IMG_FILTER_SELECTIVE_BLUR: blur the image.
IMG_FILTER_MEAN_REMOVAL: Use the average removal method to achieve the contour effect.
IMG_FILTER_SMOOTH: make the image smoother. Set the smooth level with arg1.

Isn't it amazing? php is very powerful.

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.