[PHP库]在图像上添加文字或图像水印

使用PHP和ImageMagick在图像和PDF上添加文本或图像水印。

先决条件
PHP(5.6或更高版本)
ImageMagick
ghostscript(仅用于PDF水印)
PHPImageMagick扩展是不需要.

[PHP库]在图像上添加文字或图像水印

安装

作为composer的依赖项添加

$ composer require ajaxray/php-watermark
//于PHP版本>= 5.6到<8使用v0.1.2
$ composer require ajaxray/php-watermark:v0.1.2

如何使用?

<?php
    // Initiate with source image or pdf
    $watermark = new Watermark('/path/to/source.jpg');
    
    // Customize some options (See list of supported options below)
    $watermark->withText('ajaxray.com')
       ->setFontSize(48)
       ->setRotate(30)
       ->setOpacity(.4)
       ->write('path/to/output.jpg');
    
    
    // Watermark with Image
    $watermark->withImage('path/to/logo.png')
       ->setPosition(Watermark::POSITION_BOTTOM_RIGHT)
       ->setStyle(Watermark::STYLE_IMG_DISSOLVE)
       ->write('path/to/output.jpg');

如果跳过Watermark::write()函数的输出文件名,则源文件将被覆盖。

© 版权声明
THE END
喜欢就支持一下吧
点赞9 分享
评论 抢沙发

请登录后发表评论

    blank

    暂无评论内容