Skip to content

Commit

Permalink
Added support for Craft 5
Browse files Browse the repository at this point in the history
  • Loading branch information
aelvan committed Feb 11, 2024
1 parent e14ddfd commit 697a587
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# AWS Serverless Image Handler transformer for Imager X Changelog

## 3.0.0 - 2024-02-11

### Added
- Added support for Craft 5

## 2.1.0 - 2023-06-21

### Added
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Also, an example of [how to make a custom transformer for Imager X](https://imag

## Requirements

This plugin requires Craft CMS 4.0.0 or later, [Imager X 4.0.0](https://github.com/spacecatninja/craft-imager-x/) or later,
This plugin requires Craft CMS 5.0.0-beta.1 or later, [Imager X 5.0.0-beta.1](https://github.com/spacecatninja/craft-imager-x/) or later,
and a working [AWS Serverless Image Handler](https://aws.amazon.com/solutions/implementations/serverless-image-handler/) setup.

## Usage
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "spacecatninja/imager-x-aws-serverless-transformer",
"description": "AWS Serverless Image Handler transformer for Imager X",
"type": "craft-plugin",
"version": "2.1.0",
"version": "3.0.0",
"license": "MIT",
"keywords": [
"craft",
Expand All @@ -28,8 +28,8 @@
}
],
"require": {
"php": "^8.0",
"craftcms/cms": "^4.0.0-beta",
"php": "^8.2",
"craftcms/cms": "^5.0.0-beta.1",
"ssnepenthe/color-utils": "~0.4"
},
"autoload": {
Expand Down
30 changes: 20 additions & 10 deletions src/helpers/AwsServerlessHelpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,30 @@ class AwsServerlessHelpers
*/
public static function getImageKey(Asset $image): string
{
$subfolder = null;

$fsSubfolder = null;
$volumeSubfolder = null;

try {
$fs = $image->getVolume()->getFs();
$subfolder = $fs->subfolder ?? null;
$volume = $image->getVolume();
$fs = $volume->getFs();
$fsSubfolder = $fs->subfolder ?? null;
$volumeSubfolder = $volume->getSubpath() ?? null;
} catch (\Throwable $e) {
Craft::error('Could not get filesystem from image: ' . $e->getMessage(), __METHOD__);
Craft::error('Could not get filesystem from image: '.$e->getMessage(), __METHOD__);
}

$imagePath = $image->getPath();

return ltrim(($subfolder ? rtrim(App::parseEnv($subfolder), '/') : '') . '/' . $imagePath, '/');
return ltrim(
($fsSubfolder ? trim(App::parseEnv($fsSubfolder), '/') : '').'/'.
($volumeSubfolder ? trim(App::parseEnv($volumeSubfolder), '/') : '').'/'.
$imagePath,
'/');
}

/**
* @param array $letterboxDef
*
* @return array
*/
public static function getLetterboxColor(array $letterboxDef): array
Expand Down Expand Up @@ -101,6 +109,7 @@ public static function getFormatOptions(string $format, ConfigModel $config): ar

/**
* @param array $effects
*
* @return array
*/
public static function convertEffects(array $effects): array
Expand Down Expand Up @@ -137,20 +146,21 @@ public static function convertEffects(array $effects): array

/**
* @param string $position
*
* @return string
*/
public static function getPosition(string $position): string
{
$positionArr = explode(' ', $position);
$positionArr = explode(' ', $position);

$positionCovertArr = [
0 => [0 => 'left top', 1 => 'top', 2 => 'right top'],
1 => [0 => 'left', 1 => 'center', 2 => 'right'],
2 => [0 => 'left bottom', 1 => 'bottom', 2 => 'right bottom']
];

$x = round(($positionArr[0]/100) * 2);
$y = round(($positionArr[1]/100) * 2);
$x = round(($positionArr[0] / 100) * 2);
$y = round(($positionArr[1] / 100) * 2);

return $positionCovertArr[$y][$x];
}
Expand Down

0 comments on commit 697a587

Please sign in to comment.