codeinc/watermarker-client
最新稳定版本:v1.5
Composer 安装命令:
composer require codeinc/watermarker-client
包简介
A PHP client for the watermarker service
README 文档
README
Important
This client is deprecated and is replaced by the Document Cloud PHP Client
This repository contains a PHP 8.2+ client library for watermarking images using the watermarker service.
Installation
The library is available on Packagist. The recommended way to install it is via Composer:
composer require codeinc/watermarker-client
Usage
This client requires a running instance of the watermarker service. The service can be run locally using Docker or deployed to a server.
Examples
A simple scenario to apply a watermark to an image and display the result:
use CodeInc\WatermarkerClient\WatermarkerClient; use CodeInc\WatermarkerClient\Exception; $apiBaseUri = 'http://localhost:3000/'; $anImage = '/path/to/local/image.png'; $theWatermark = '/path/to/local/watermark.png'; try { $client = new WatermarkerClient($apiBaseUri); // apply the watermark $watermarkedImageStream = $client->apply( $client->createStreamFromFile($anImage), $client->createStreamFromFile($theWatermark), ); // display the watermarked image header('Content-Type: image/png'); echo (string)$watermarkedImageStream; } catch (Exception $e) { // handle exception }
A mire complex scenario to apply a watermark to an image with options and save the result to a file:
use CodeInc\WatermarkerClient\WatermarkerClient; use CodeInc\WatermarkerClient\ConvertOptions; use CodeInc\WatermarkerClient\Position; use CodeInc\WatermarkerClient\Format; $apiBaseUri = 'http://localhost:3000/'; $theImageStream = '/path/to/local/image.png'; $theWatermarkStream = '/path/to/local/watermark.png'; $theDestinationFile = '/path/to/local/destination.png'; $convertOption = new ConvertOptions( size: 50, position: Position::topRight, format: Format::jpg, quality: 80, blur: 3, opacity: 75 ); try { $streamFactory = Psr17FactoryDiscovery::findStreamFactory(); $client = new WatermarkerClient($apiBaseUri); // apply the watermark $watermarkedImageStream = $client->apply( $client->createStreamFromFile($theImageStream), $client->createStreamFromFile($theWatermarkStream), $convertOption ); // save the watermarked image $client->saveStreamToFile($watermarkedImageStream, $theDestinationFile); } catch (Exception $e) { // handle exception }
License
The library is published under the MIT license (see LICENSE file).
统计信息
- 总下载量: 17
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-02-24