Get the App
SLTechnology News&Howtos  ›  Development  › 

How to modify the color of a picture by php

Shulou Source: shulou.com Published: 2022-06-03 10:39:12 10月02日 Update

Php how to modify the color of the picture, in view of this problem, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.

Php method to modify the color of the picture: 1, to create a PHP example file; 2, through the "img_replace_color ('# 00000000000000mm recording f30145," upload/001.png "," upload/out.png "); method to replace the color in the picture.

This article operating environment: Windows7 system, PHP7.1, Dell G3 computer.

How does php change the color of the picture?

Php replaces the color of the pixels in the picture

Replace one color in the picture with another color

Other colors can also be dealt with, can be removed by themselves and can only replace the positive color.

The background is transparent and the background is white.

/ / replace the colors in the picture / / img_replace_color ('# 000000mlt / f30145, "upload/001.png", "upload/out.png"); / / 255255255127 clear 0000 black and 255heroes 255pr 055pr 055pr 0 [103pr 103pr 03pl 06pr 0 Gray] function img_replace_color ($seachcolor,$replacecolor,$file,$outfile='') {$im=imagecreatefrompng ($file); $newim = imagecreatetruecolor (imagesx ($im), imagesy ($im)); / / create a canvas imagesavealpha ($newim, true) / / background transparent $background = imagecolorallocatealpha ($newim, 255,255,255127); imagefill ($newim,0,0,$background); / / background transparent for ($yellow0% 16) {$r = $c% 16; $c = ($c / 16) > > 0; array_push ($hexAr, $hex [$r]) } array_push ($hexAr, $hex [$c]); $ret = array_reverse ($hexAr); $item = implode ('', $ret); $item = str_pad ($item, 2, '0mm, STR_PAD_LEFT); $hexColor. = $item;} return $hexColor } / * * hexadecimal to RGB * / function hex2rgb ($hexColor) {$color = str_replace ('#','', $hexColor) If (strlen ($color) > 3) {$rgb = array ('r' = > hexdec (substr ($color, 0,2)),'g' = > hexdec (substr ($color, 2,2)),'b' = > hexdec (substr ($color, 4,2) } else {$color = $hexColor; $r = substr ($color, 0,1). Substr ($color, 0,1); $g = substr ($color, 1,1). Substr ($color, 1,1); $b = substr ($color, 2,1). Substr ($color, 2,1); $rgb = array ('r' = > hexdec ($r),'g' = > hexdec ($g),'b' = > hexdec ($b));} return $rgb;}

The answer to the question about how php modifies the color of the picture is shared here. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.

Tags: Color picture background hexadecimal method question pixel more canvas processing help solution easy easy content character string boy buddy file Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux NVidia Shulou Tech Info Shulou Information vpn