Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Utilize official imgix URL Builder #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
vendor
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ In any config file or the default `site/config/config.php`:
```php
return [
'imgix' => true,
'imgix.domain' => 'https://project-name.imgix.net/',
'imgix.domain' => 'example.imgix.net',
'imgix.secure_token' => 'examplekey', // https://docs.imgix.com/setup/securing-images
'imgix.defaults' => [
'auto' => 'compress',
],
'q' => 90,
'lossless' => 1
]
];
```

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
}
],
"require": {
"getkirby/composer-installer": "^1.1"
"getkirby/composer-installer": "^1.1",
"imgix/imgix-php": "^3.3"
},
"extra": {
"installer-name": "imgix"
Expand Down
106 changes: 106 additions & 0 deletions composer.lock

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

24 changes: 15 additions & 9 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
<?php
require(__DIR__ . '/vendor/autoload.php');

use Kirby\Cms\App;
use Kirby\Cms\File;
use Kirby\Cms\FileVersion;
use Imgix\UrlBuilder;

function endsWith($haystack, $needle) {
return substr($haystack,-strlen($needle))===$needle;
function endsWith($haystack, $needle)
{
return substr($haystack, -strlen($needle)) === $needle;
}

function imgix($url, $params = [])
{
$builder = new UrlBuilder(option('imgix.domain'));

if (option('imgix.secure_token')) {
$builder->setSignKey(option('imgix.secure_token'));
}

if (is_object($url) === true) {
$url = $url->url();
}
Expand All @@ -34,16 +43,13 @@ function imgix($url, $params = [])

foreach ($params as $key => $value) {
if (isset($map[$key]) && !empty($value)) {
$options[] = $map[$key] . '=' . $value;
}
elseif (!isset($map[$key]) && !empty($value)) {
$options[] = $key . '=' . $value;
$options[$map[$key]] = $value;
} elseif (!isset($map[$key]) && !empty($value)) {
$options[$key] = $value;
}
}

$options = implode('&', $options);

return option('imgix.domain') . $path . '?' . $options;
return $builder->createURL($path, $params);
}

Kirby::plugin('diesdasdigital/imgix', [
Expand Down