Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
first version !
Browse files Browse the repository at this point in the history
  • Loading branch information
joanfabregat committed Feb 24, 2024
1 parent 62cd656 commit 3f00c72
Show file tree
Hide file tree
Showing 23 changed files with 4,012 additions and 18 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.DS_Store
/vendor
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/copyright/Code_Inc__open_source.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/copyright/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

80 changes: 80 additions & 0 deletions .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/phpunit.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 62 additions & 0 deletions .idea/watermarker-php-client.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* [email protected]
22 changes: 4 additions & 18 deletions LICENSE
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.
87 changes: 87 additions & 0 deletions README.md
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).
45 changes: 45 additions & 0 deletions composer.json
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"
}
}
Loading

0 comments on commit 3f00c72

Please sign in to comment.