Blogger Information
Blog 34
fans 0
comment 0
visits 39104
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
tp5.1 一张图添加多个水印
黄健的博客
Original
1902 people have browsed it

我开始是直接循环处理添加水印,定义好循环的次数。


$image = \think\Image::open('./image.png');
$size=$image->size();
$wz=array(); //水印图片坐标数组
$hnum=floor($size[1]/10); //根据高度循环10次
$wnum=floor($size[0]/2);
for($w=0;$w<$hnum;$w++){
                $wz[1]=$w*$hnum;
                $wz[0]=200;
                $image->water('./logo.png',$wz,20)->save('water_image.png');
                $wz[0]=(1*$wnum)+200;
                $image->water('./logo.png',$wz,20)->save('water_image.png');
            }

这样循环出来,等了很久都没有反应。后来公司大佬看了我写的,然后告诉我, save()方法是保存文件的方法,每次循环一次就保存一下,所以就很慢很慢。


接下来换了种写法,我只在循环里用添加水印的方法。


for($w=0;$w<$hnum;$w++){
                $wz[1]=$w*$hnum;
                $wz[0]=200;
                $image->water('./logo.png',$wz,20);
                $wz[0]=(1*$wnum)+200;
                $image->water('./logo.png',$wz,20);
            }
            $image->save('.'.$uploadPath.date("Ymd").'/text_image.png');

这样就大概10多秒就可以,不过在保存图片之前需要  检查一下文件夹是否存在。


    

    

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post