-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.DS_Store | ||
/vendor |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* [email protected] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,7 @@ | ||
MIT License | ||
Copyright 2024 Code Inc. / Joan Fabrégat <[email protected]> | ||
|
||
Copyright (c) 2024 Code Inc. | ||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# watermarker PHP client | ||
|
||
This repository contains a PHP 8.2+ client library for watermarking images using the [watermarker](https://github.com/codeinchq/watermarker) service. | ||
|
||
## Installation | ||
|
||
The recommended way to install the library is through [Composer](http://getcomposer.org): | ||
|
||
```bash | ||
composer require codeinc/watermarker-client | ||
``` | ||
|
||
## Usage | ||
|
||
This client requires a running instance of the [watermarker](https://github.com/codeinchq/watermarker) service. The service can be run locally [using Docker](https://hub.docker.com/r/codeinchq/watermarker) or deployed to a server. | ||
|
||
### Examples | ||
|
||
#### A simple scenario to apply a watermark to an image and display the result: | ||
```php | ||
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: | ||
```php | ||
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`](LICENSE) file). |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"name": "codeinc/watermarker-client", | ||
"version": "v1.0", | ||
"description": "A PHP client for the watermarker service", | ||
"homepage": "https://github.com/codeinchq/watermarker-php-client", | ||
"type": "library", | ||
"license": "MIT", | ||
"require": { | ||
"php": ">=8.3", | ||
"php-http/discovery": "^1.19", | ||
"psr/http-client": "^1.0", | ||
"php-http/multipart-stream-builder": "^1.3" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"CodeInc\\WatermarkerClient\\": "src" | ||
} | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"CodeInc\\WatermarkerClient\\Tests\\": "tests/" | ||
} | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Joan Fabrégat", | ||
"email": "[email protected]", | ||
"homepage": "https://www.codeinc.co", | ||
"role": "developer" | ||
} | ||
], | ||
"config": { | ||
"preferred-install": { | ||
"*": "dist" | ||
}, | ||
"allow-plugins": { | ||
"php-http/discovery": true | ||
} | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^11", | ||
"spatie/ray": "^1.41", | ||
"php-http/guzzle7-adapter": "^1.0" | ||
} | ||
} |