@@ -377,24 +377,32 @@ public function thumb($width, $height, $type = self::THUMB_SCALING)
377
377
/**
378
378
* 添加水印
379
379
*
380
- * @param string $source 水印图片路径
380
+ * @param string $source 水印图片路径,或者string格式的图片字符串
381
381
* @param int|array $locate 水印位置
382
382
* @param int $alpha 透明度
383
383
* @return $this
384
384
*/
385
385
public function water ($ source , $ locate = self ::WATER_SOUTHEAST , $ alpha = 100 )
386
386
{
387
- if (!is_file ($ source )) {
388
- throw new ImageException ('水印图像不存在 ' );
389
- }
390
- //获取水印图像信息
391
- $ info = getimagesize ($ source );
392
- if (false === $ info || (IMAGETYPE_GIF === $ info [2 ] && empty ($ info ['bits ' ]))) {
393
- throw new ImageException ('非法水印文件 ' );
387
+ if (strlen ($ source ) < 200 ){
388
+ if (!is_file ($ source )) {
389
+ throw new ImageException ('水印图像不存在 ' );
390
+ }
391
+ //获取水印图像信息
392
+ $ info = getimagesize ($ source );
393
+ if (false === $ info || (IMAGETYPE_GIF === $ info [2 ] && empty ($ info ['bits ' ]))) {
394
+ throw new ImageException ('非法水印文件 ' );
395
+ }
396
+ //创建水印图像资源
397
+ $ fun = 'imagecreatefrom ' . image_type_to_extension ($ info [2 ], false );
398
+ $ water = $ fun ($ source );
399
+ }else {
400
+ $ water = imagecreatefromstring ($ source );
401
+ $ info = [
402
+ imagesx ($ water ),
403
+ imagesy ($ water ),
404
+ ];
394
405
}
395
- //创建水印图像资源
396
- $ fun = 'imagecreatefrom ' . image_type_to_extension ($ info [2 ], false );
397
- $ water = $ fun ($ source );
398
406
//设定水印图像的混色模式
399
407
imagealphablending ($ water , true );
400
408
/* 设定水印位置 */
0 commit comments