Php adds Gray and transparent effects to images _ PHP Tutorial

Source: Internet
Author: User
Tags image identifier imagecopy
Php adds Gray and transparent effects to images. This article will introduce you to an article about the gray and transparent effects of php on images. I hope this method will be helpful to you. Principle: 1. calculate the size of the original image. create an article to introduce the gray and transparent effects of php on images. I hope this method will be helpful to you.

Principle:

1. calculate the size of the original image
2. create a translucent image of the same size
3. use the imagecopy () method to merge the newly created translucent image with the original image.

The code is as follows:

/* Add Gray and transparent effects to images in php */
$ Imfile = './0.jpg'; // source image
$ Origim = imagecreatefromjpeg ($ imfile); // create an image from a JPEG file or URL

$ W = imagesx ($ origim); // source image width
$ H = imagesy ($ origim); // The height of the source image

$ Newimg = imagecreatetruecolor ($ w, $ h); // returns an image identifier, representing a black image of x_size and y_size. Imagecreatetruecolor //

$ Color = imagecolorallocatealpha ($ newimg,); // assign color + alpha to an image; same as imagecolorallocate (), but with an additional transparency parameter alpha, the value ranges from 0 to 127. 0 indicates full opacity, and 127 indicates full transparency.

Imagecolortransparent ($ newimg, $ color); // define a color as transparent

Imagefill ($ newimg, 0, 0, $ color); // fill in the area; resource $ image, int $ x, int $ y, int $ color

Imagecopy ($ origim, $ newimg, 0, 0, $ w, $ h); // Copy part of the image. start the coordinates of the src_im image from src_x, src_y, part of the width src_w and height src_h is copied to the position where the coordinates of dst_im are dst_x and dst_y.

Imagejpeg ($ origim, './2.jpg'); // output the image to a browser or file .; Resource $ image [, string $ filename [, int $ quality]
?>

I hope this method will be helpful to you. Principle: 1. calculate the size of the original image 2. create a phase...

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.