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.