PHP to achieve a picture with a gray translucent effect of the method _php skills

Source: Internet
Author: User

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.

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.