The content of this article is about how to use php code to realize the cutout (code) of the seal. The content is very detailed. Friends in need can refer to it. I hope it can help you.
I can cut out the seal with red text on the white background. I use PHP and the framework is Laravel. Please adjust other frameworks by yourself. You can also cut out other colors. Just change the rgb parameter judgment inside. The final cutout effect is that the white background becomes transparent, and then only the red stamp is left, which can be placed on other pages to form a stamp effect. . The code is written by myself and may have bugs, but it is still ok for testing. Please test and optimize it yourself if you use it at work. (After my own test and comparison, I can achieve a cutout effect similar to that of PS)
function getStamp(){ $path = storage_path('2018052411173848180.png'); $image = file_get_contents($path); $info = getimagesize($path); $im = imagecreatefromstring($image); $width = $info[0]; $height = $info[1]; for($i=0;$i<$height;$i+=1){ for($j=0;$j<$width;$j+=1){ $rgb = ImageColorAt($im, $j, $i); $r = ($rgb >> 16) & 0xFF; $g = ($rgb >> 8) & 0xFF; $b = $rgb & 0xFF; echo $r.'.'.$g.'.'.$b.'.='.$rgb.'<br>x='.$j.', y='.$i.'<br>'; if(intval($r)>220 && $g >220 && $b>220){ $hex = imagecolorallocate($im, 255, 255, 255); imagesetpixel($im,$j, $i, $hex); } } } $white = imagecolorallocate($im , 255 , 255 , 255);//拾取白色 imagefill($im , 0 , 0 , $white);//把画布染成白色 imagecolortransparent($im , $white ) ;//把图片中白色设置为透明色 imagepng($im , storage_path('test2.png'));//生成图片 return false; }
Related recommendations:
PHP code example to implement Alipay app payment and asynchronous notification
php socket programming commonly used functions and implementation of simple c/s interactionThe above is the detailed content of How to use php code to realize cutout of seal (code). For more information, please follow other related articles on the PHP Chinese website!