General steps:
1. Scale the image to improve efficiency
2. Grayscale the image
3. Calculate the edge based on brightness
The third step is the most critical, and there are many methods The direct contrast used here is between adjacent brightnesses.
Recommended learning: "PHP Video Tutorial"
Usage:
Installation
composer require lizhichao/one-img
Use
$img_path = '1.jpg'; $img = new \OneImg\Border(); $img->setImg($img_path) ->scale(300, 300) ->outline() ->save(); //输出到浏览器
Effect
Code warehouse
https://github.com/lizhichao/doImg