webman使用 intervention/image 生成带水印/二维码的图片
一、使用composer下载扩展包
composer require intervention/image
二、实现代码
use Intervention\Image\ImageManager; class Image { private $image; public function __construct() { $this->image = new ImageManager(array( 'driver' => 'imagick' )); } /* * 分享图片添加二维码 * * 基底图片 * 尺寸:750 * 1200 * 空白二维码位置 top:100, left:50 * 空白二维码尺寸 200 * 200 * */ public function create($qrcode) { $base_image = public_path() . "/images/share_bg.png"; $file_path = runtime_path() . "/temp/share/"; if (!is_dir($file_path)) { mkdir($file_path, 0755, true); } $share_image = md5($qrcode) . mt_rand(0, 9999) . ".png"; $this->image ->make($base_image) ->resize(750, 1200) ->insert($qrcode, 'top-left', 50, 100) ->save($file_path . $share_image); return $file_path . $share_image; } }
备注: 图片添加水印类同