Home > Backend Development > PHP Problem > How to remove image color in php

How to remove image color in php

藏色散人
Release: 2023-03-08 16:56:01
Original
1642 people have browsed it

php method to remove the color of the picture: first create a PHP sample file; then use the "imagecolortransparent($image,imagecolorallocate(...));" method to remove the color in the picture and make it transparent That’s it.

How to remove image color in php

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

PHP How to remove some colors from a picture, Make it transparent?

Use imagecolortransparent

The first of the two parameters is the picture, and the second is the matching color

The matching color is ImageColorAllocate

Complete demonstration, for example:

imagecolortransparent($image,imagecolorallocate($image,255,255,255));
Copy after login

This is to turn the matched white color into transparent

Function introduction:

For some colors, use a loop to make the matching color transparent

imagecolortransparent — Define a color as transparent.

Syntax

int imagecolortransparent ( resource $image [, int $color ] )
Copy after login

imagecolortransparent() Sets the transparent color in image to color. image is the image identifier returned by imagecreatetruecolor(), and color is the color identifier returned by imagecolorallocate().

Note: Transparent color is an attribute of the image, and transparency is not an attribute of color. Once you set a color to be transparent, any areas in the image that were previously painted that color become transparent.

Returns the identifier of the new transparent color. If color is omitted, returns the identifier of the current transparent color.

Note: Transparency can only be copied via imagecopymerge() and true color images, not imagecopy() or palette images.

[Recommended learning: "PHP Video Tutorial"]

The above is the detailed content of How to remove image color in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template