This article illustrates the method that PHP implements to add gray translucent effect to the picture. Share to everyone for your reference. The implementation methods are as follows:
Principle:
1. First calculate the size of the original picture
2. Create translucent pictures of the same size
3. Use the Imagecopy () method to merge the newly created translucent pictures with the original artwork
The specific implementation code is as follows:
Copy Code code as follows:
<?php
/*php to the picture with the gray transparent effect * *
$imfile = './0.jpg ';//original artwork
$origim = Imagecreatefromjpeg ($imfile);//Create a new image from a JPEG file or URL
$w =imagesx ($ORIGIM);//Original width
$h =imagesy ($ORIGIM);//Original height
$newimg = Imagecreatetruecolor ($w, $h);//Returns an image identifier that represents a black image of x_size and y_size size. imagecreatetruecolor//
$color =imagecolorallocatealpha ($newimg, 0,0,0,75);//Assign color + alpha to an image; Same as Imagecolorallocate (), but an extra transparency parameter alpha with a value ranging from 0 to 127. 0 means completely opaque, and 127 means full transparency.
Imagecolortransparent ($newimg, $color);//define a color as a transparent color
Imagefill ($newimg, 0,0, $color);//region fill; resource $image, int $x, int $y, int $color
Imagecopy ($origim, $newimg, 0,0, 0, 0, $w, $h);//Copy part of the image, start the coordinates of the src_im image from the src_x,src_y, the width is src_w, and the height is part of the src_h copy to the Dst_im The coordinates in the image are dst_x and dst_y positions.
Imagejpeg ($origim, './2.jpg ');//output image to browser or file. Resource $image [, String $filename [, int $quality]]
?>
I hope this article will help you with your PHP program design.