Home >Backend Development >PHP Tutorial >How to add gray translucent effect to pictures in PHP, _PHP tutorial

How to add gray translucent effect to pictures in PHP, _PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:16:341389browse

How to add gray translucency to images in php,

The example in this article describes how to add a gray translucent effect to images in PHP. Share it with everyone for your reference. The specific implementation method is as follows:

Principle:

1. First calculate the size of the original image
2. Create translucent images of the same size
3. Use the imagecopy() method to merge the newly created semi-transparent image with the original image

The specific implementation code is as follows:

Copy code The code is as follows:
/*php adds gray transparency effect to the image*/
$imfile = './0.jpg';//Original image
$origim = imagecreatefromjpeg($imfile);//Create a new image from a JPEG file or URL

$w=imagesx($origim);//Width of original image
$h=imagesy($origim);//Height of original image

$newimg = imagecreatetruecolor($w, $h);//Returns an image identifier, representing a black image of size x_size and y_size. imagecreatetruecolor// 

$color=imagecolorallocatealpha($newimg,0,0,0,75);//Assign color + alpha to an image; Same as imagecolorallocate(), but with an additional transparency parameter alpha, whose value ranges from 0 to 127 . 0 means completely opaque, 127 means completely transparent.

imagecolortransparent($newimg,$color);//Define a color as a transparent color

imagefill($newimg,0,0,$color);//Area filling;resource $image, int $x, int $y, int $color

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

imagejpeg($origim, './2.jpg');//Output the image to the browser or file. ;resource $image [, string $filename [, int $quality ]]
?>

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/897015.htmlTechArticleHow to add gray translucency to images in php. This article describes how to add gray translucency to images in php. effect method. Share it with everyone for your reference. The specific implementation methods are as follows...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn