Skip to content

Commit 91e0fd8

Browse files
πŸš€
0 parents  commit 91e0fd8

22 files changed

Lines changed: 1888 additions & 0 deletions

β€Ž.editorconfigβ€Ž

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# Top-most EditorConfig file
4+
root = true
5+
6+
# All files
7+
[*]
8+
charset = utf-8
9+
end_of_line = lf
10+
insert_final_newline = true
11+
trim_trailing_whitespace = true
12+
indent_style = tab
13+
14+
# Markdown files
15+
[*.md]
16+
trim_trailing_whitespace = false
17+
18+
[*.{md,yaml,yml}]
19+
indent_size = 2
20+
indent_style = space

β€Ž.github/workflows/ci.yamlβ€Ž

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
name: CI
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches:
7+
- main
8+
pull_request:
9+
10+
jobs:
11+
ecs:
12+
name: ECS Check
13+
runs-on: ubuntu-latest
14+
env:
15+
DEFAULT_COMPOSER_FLAGS: "--no-interaction --no-ansi --no-progress"
16+
steps:
17+
- uses: actions/checkout@v4
18+
- uses: shivammathur/setup-php@v2
19+
with:
20+
php-version: 8.2
21+
- run: composer install --prefer-dist --no-progress
22+
- name: Run ecs check
23+
run: |
24+
vendor/bin/ecs --memory-limit=1G --no-progress-bar
25+
rector:
26+
name: Rector dry-run
27+
runs-on: ubuntu-latest
28+
env:
29+
DEFAULT_COMPOSER_FLAGS: "--no-interaction --no-ansi --no-progress"
30+
steps:
31+
- uses: actions/checkout@v4
32+
- uses: shivammathur/setup-php@v2
33+
with:
34+
php-version: 8.2
35+
- run: composer install --prefer-dist --no-progress
36+
- name: Run rector --dry-run
37+
run: |
38+
vendor/bin/rector --memory-limit=1G --no-progress-bar --dry-run
39+
phpstan:
40+
name: PHPStan
41+
runs-on: ubuntu-latest
42+
env:
43+
DEFAULT_COMPOSER_FLAGS: "--no-interaction --no-ansi --no-progress"
44+
steps:
45+
- uses: actions/checkout@v4
46+
- uses: shivammathur/setup-php@v2
47+
with:
48+
php-version: 8.2
49+
- run: composer install --prefer-dist --no-progress
50+
- name: Run phpstan
51+
run: |
52+
vendor/bin/phpstan --memory-limit=1G
53+
pest:
54+
name: Pest
55+
runs-on: ubuntu-latest
56+
env:
57+
DEFAULT_COMPOSER_FLAGS: "--no-interaction --no-ansi --no-progress"
58+
steps:
59+
- uses: actions/checkout@v4
60+
- uses: shivammathur/setup-php@v2
61+
with:
62+
php-version: 8.2
63+
- run: composer install --prefer-dist --no-progress
64+
- name: Run pest
65+
run: |
66+
vendor/bin/pest

β€Ž.gitignoreβ€Ž

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
*.log
2+
*.bak
3+
*.DS_Store
4+
*.orig
5+
*Thumbs.db
6+
vendor/
7+
.vscode
8+
.idea
9+
.php_cs.cache
10+
node_modules
11+
composer.lock

β€ŽCHANGELOG.mdβ€Ž

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Changelog
2+
3+
## 1.0.3 - 2025-04-28
4+
5+
- Add support to optionally base64 encode the source filename
6+
7+
## 1.0.2 - 2025-04-22
8+
9+
- Ensure methods signatures correspond with processing options
10+
11+
## 1.0.1 - 2025-04-22
12+
13+
- Ensure options requiring base64 encoding are properly encoded
14+
15+
## 1.0.0 - 2025-04-21
16+
17+
- Initial release

β€ŽLICENSE.mdβ€Ž

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# The MIT License (MIT)
2+
3+
Copyright (c) 2025 Foster Commerce
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

β€ŽREADME.mdβ€Ž

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
# smallpics-php
2+
3+
A PHP client library for generating URLs with SmallPics.io. This package provides a simple way to build URLs with SmallPics.io processing options.
4+
5+
## Installation
6+
7+
```bash
8+
composer require smallpics/smallpics-php
9+
```
10+
11+
## Usage
12+
13+
### Creating Processing Options
14+
15+
```php
16+
use smallpics\smallpics\Options;
17+
18+
// Create a new Options object
19+
$options = new Options();
20+
21+
// Set options with individual setters
22+
$options
23+
->setWidth(300)
24+
->setHeight(400);
25+
26+
// Generate the query string parameters
27+
echo $options->toString();
28+
// Output: "width=300&height=400"
29+
30+
// Options object can also be used directly in a string context
31+
echo $options;
32+
// Output: "width=300&height=400"
33+
```
34+
35+
### Alternative Initialization
36+
37+
It is possible to initialize the Options object with an associative array. The keys of the array are the option names and the values are the option values.
38+
39+
The values can either be a single value, an array of values, or an associative array of values.
40+
41+
- When a single value is used, it is passed as the first argument to the setter method.
42+
- When an array of values is used, they are destructured as passed as arguments in order to the setter method.
43+
- When an associative array is used, the key/value pairs are destructured and passed in as named arguments to the setter method.
44+
45+
```php
46+
// Create Options object with array of values
47+
$options = new Options([
48+
'width' => 300,
49+
'height' => 400,
50+
'resize' => [
51+
'width' => 300,
52+
'height' => 400,
53+
'enlarge' => false,
54+
'resize_type' => 'fill',
55+
],
56+
'gravity' => 'sm',
57+
'png_options' => [
58+
'interlaced' => true,
59+
'quantize' => false,
60+
],
61+
]);
62+
```
63+
64+
### Building URLs
65+
66+
```php
67+
use smallpics\smallpics\Options;
68+
use smallpics\smallpics\UrlBuilder;
69+
70+
// Create options object
71+
$options = new Options();
72+
$options
73+
->setQuality(80)
74+
->setFormat('png');
75+
76+
// Create URL builder (without signing, with plain URLs)
77+
$builder = new UrlBuilder('https://images.my-origin.com', null, null, false);
78+
79+
// Build URL
80+
$imageUrl = 'https://example.com/images/image.jpg';
81+
$url = $builder->buildUrl($imageUrl, $options);
82+
83+
echo $url;
84+
// Output: https://images.my-origin.com/unsafe/preset:sharp/resize:fill:300:400:0/gravity:sm/quality:80/format:png/plain/https://example.com/images/image.jpg
85+
```
86+
87+
### Encoded URLs
88+
89+
```php
90+
use smallpics\smallpics\Options;
91+
use smallpics\smallpics\UrlBuilder;
92+
93+
// Create options object
94+
$options = new Options();
95+
$options
96+
->setWidth(300)
97+
->setHeight(400);
98+
99+
// Create URL builder
100+
$builder = new UrlBuilder('https://images.my-origin.com');
101+
102+
// Build URL with encoded source
103+
$imageUrl = 'images/image.jpg';
104+
$url = $builder->buildUrl($imageUrl, $options);
105+
106+
echo $url;
107+
// Output: https://images.my-origin.com/images/image.jpg?width=300&height=400
108+
```
109+
110+
### Signed URLs
111+
112+
```php
113+
// Create URL builder with signing keys
114+
$key = '0123456789abcdef0123456789abcdef';
115+
$salt = 'fedcba9876543210fedcba9876543210';
116+
$builder = new UrlBuilder('https://images.my-origin.com', $key, $salt);
117+
118+
// Build signed URL
119+
$imageUrl = 'images/image.jpg';
120+
$url = $builder->buildUrl($imageUrl, $options);
121+
122+
echo $url;
123+
// Output will include a signature: https://images.my-origin.com/images/image.jpg?width=300&height=400&signature=[signature]
124+
```
125+
126+
## Development
127+
128+
### Testing
129+
130+
This package uses [Pest PHP](https://pestphp.com/) for testing. To run the tests:
131+
132+
```bash
133+
composer test
134+
```
135+
136+
or
137+
138+
```bash
139+
vendor/bin/pest
140+
```

β€Žcomposer.jsonβ€Ž

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"name": "smallpics/smallpics-php",
3+
"description": "A PHP client library for generating URLs with SmallPics.io",
4+
"type": "library",
5+
"version": "0.1.0",
6+
"keywords": [
7+
"smallpics",
8+
"php",
9+
"library",
10+
"images",
11+
"processing"
12+
],
13+
"license": "proprietary",
14+
"support": {
15+
"email": "support@smallpics.io",
16+
"issues": "https://github.com/smallpics/smallpics-php/issues?state=open",
17+
"source": "https://github.com/smallpics/smallpics-php",
18+
"docs": "https://github.com/smallpics/smallpics-php/blob/develop/README.md"
19+
},
20+
"require": {
21+
"php": ">=8.2.0"
22+
},
23+
"require-dev": {
24+
"fostercommerce/ecs": "dev-main",
25+
"fostercommerce/rector": "dev-main",
26+
"pestphp/pest": "^3.8",
27+
"phpstan/phpstan": "^1.12"
28+
},
29+
"autoload": {
30+
"psr-4": {
31+
"smallpics\\smallpics\\": "src/"
32+
}
33+
},
34+
"autoload-dev": {
35+
"psr-4": {
36+
"smallpics\\smallpics\\tests\\": "tests/"
37+
}
38+
},
39+
"config": {
40+
"sort-packages": true,
41+
"allow-plugins": {
42+
"yiisoft/yii2-composer": true,
43+
"craftcms/plugin-installer": true,
44+
"pestphp/pest-plugin": true
45+
}
46+
},
47+
"prefer-stable": true,
48+
"minimum-stability": "dev",
49+
"scripts": {
50+
"phpstan": "phpstan --memory-limit=1G",
51+
"ecs:check": "ecs check --ansi --memory-limit=1G",
52+
"ecs:fix": "ecs check --ansi --fix --memory-limit=1G",
53+
"rector:fix": "rector process --config rector.php",
54+
"rector:dry-run": "rector process --dry-run --config rector.php",
55+
"test": "pest"
56+
}
57+
}

β€Žecs.phpβ€Ž

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use fostercommerce\ecs\ECSConfig;
6+
7+
return ECSConfig::configure()
8+
->withPaths([
9+
__DIR__ . '/src',
10+
__DIR__ . '/tests',
11+
__FILE__,
12+
]);

β€Žphpstan.neonβ€Ž

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
parameters:
2+
paths:
3+
- src
4+
level: 9

β€Žphpunit.xmlβ€Ž

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
>
7+
<testsuites>
8+
<testsuite name="Unit">
9+
<directory>tests/Unit</directory>
10+
</testsuite>
11+
</testsuites>
12+
<source>
13+
<include>
14+
<directory>src</directory>
15+
</include>
16+
</source>
17+
</phpunit>

0 commit comments

Comments
Β (0)