Php implementation to add gray translucent effects to images

Source: Internet
Author: User
Tags image identifier imagecopy
This article mainly introduces how php can add gray translucent effects to images. It involves image operations and is a very practical technique. For more information, see

This article mainly introduces how php can add gray translucent effects to images. It involves image operations and is a very practical technique. For more information, see

This example describes how php can add gray-translucent effects to images. Share it with you for your reference. The specific implementation method is as follows:

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 specific implementation code is as follows:

The Code is as follows:

<? Php
/* 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 completely opaque, and 127 indicates completely transparent.

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 article will help you with PHP programming.

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.