Skip to content

Commit

Permalink
Increment beta version, and housekeeping
Browse files Browse the repository at this point in the history
  • Loading branch information
croxton committed Feb 26, 2021
1 parent cbb4b03 commit 84d8725
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Imgixer plugin for Craft CMS 3.x

Generate Imgix URLs. Optionally, speed up your templates and control panel by swapping Craft's native image transforms with Imgix rendering.
The most flexible Imgix URL generator for Craft CMS.

* Generate Imgix URLs with convenient methods for responsive images.
* *New*: Speed up your templates and control panel by swapping Craft's native image transforms with Imgix rendering.
* *New*: [Servd.host](https://servd.host) users - use Servd's built-in image transforms instead of Imgix.

![Screenshot](resources/img/plugin-logo.png)

Expand Down Expand Up @@ -157,9 +161,9 @@ return [
```
## Using Imgixer with Servd.host asset sources

There are several ways to use Imgixer with Servd.host asset sources, and benefit from Servd's automatic environment prefixing environment (generated URLs will be prefixed with `local`, `staging` or `production`).
There are several ways to use Imgixer with [Servd.host](https://servd.host) asset sources, and benefit from Servd's automatic environment prefixing (generated URLs are prefixed with `local`, `staging` or `production`).

In both cases please first install [Servd Assets and Helpers](https://github.com/servdhost/craft-asset-storage).
With either option, you will first need to install [Servd Assets and Helpers](https://github.com/servdhost/craft-asset-storage).

### 1. Using an Imgix Web Folder source

Expand All @@ -185,7 +189,7 @@ In both cases please first install [Servd Assets and Helpers](https://github.com

### 2. Use Servd's own image transformation service

Servd provides it's own transformation service that supports a subset of Imgix's image transformation features, that nonetheless covers most use cases. This does NOT require an Imgix account, but note that it does consume the Servd resources allocated to your plan.
Servd provides it's own image transformation service that supports a subset of Imgix's image transformation features, that nonetheless covers most use cases. This does NOT require an Imgix account, but note that it does consume the Servd resources allocated to your plan.

Create a source in `imgixer.php` config, adding `servd` as the asset provider. Do not set a domain:

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "croxton/imgixer",
"description": "Generate Imgix URLs.",
"type": "craft-plugin",
"version": "1.0.2-beta.2",
"version": "1.0.2-beta.3",
"keywords": [
"craft",
"cms",
Expand Down
23 changes: 3 additions & 20 deletions src/providers/ServdProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,30 +60,13 @@ protected function servdTransformUrl($source, Asset $asset, $params) {
// Get the volume
$volume = $asset->getVolume();

// merge any default params
// Merge any default params
if ( isset($source['defaultParams'])) {
$params = array_merge($source['defaultParams'], $params);
}

// if 'ar' param set and either 'h' or 'w',
// calculate the corresponding dimension if it is missing
if (isset($params['ar'])) {
$ar = 0;
$ar = array_map('intval', explode(':', $params['ar']));
if ( isset($ar[0]) && isset($ar[1])) {
$ar = $ar[0]/$ar[1];
}
if ($ar > 0) {
if ( isset($params['w']) && ! isset($params['h']) ) {
$params['h'] = intval($params['w']) / $ar;
} elseif ( isset($params['h']) && ! isset($params['w']) ) {
$params['w'] = intval($params['h']) * $ar;
}
}
}

// Only allow params supported by Servd
$allowedParams = array_flip(array('w', 'h', 'q', 'fm', 'auto', 'fit', 'crop', 'fp-x', 'fp-y', 'fill-color', 'dpr', 'dm'));
$allowedParams = array_flip(array('w', 'h', 'q', 'fm', 'auto', 'fit', 'crop', 'fp-x', 'fp-y', 'fill-color', 'dpr', 'ar', 'dm'));
$params = array_intersect_key($params, $allowedParams);

// Full path of asset on the CDN platform
Expand Down Expand Up @@ -129,7 +112,7 @@ protected function servdTransformUrl($source, Asset $asset, $params) {
*/
protected function servdImgixUrl($source, Asset $asset, $params) {

// Get the full path to the iamhe
// Get the full path to the image
$img = $asset->path;
$volume = $asset->getVolume();
$img = ltrim(trim($volume->subfolder, '/') . '/' . $img, '/');
Expand Down

0 comments on commit 84d8725

Please sign in to comment.