Skip to content

Commit

Permalink
Fixed bug when using pre-defined image transforms
Browse files Browse the repository at this point in the history
  • Loading branch information
lindseydiloreto committed Oct 1, 2024
1 parent 3f0117a commit e85cb2f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 23 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

## Unreleased

### Fixed
- Fixed bug encountered when using pre-defined image transforms. ([#43](https://github.com/doublesecretagency/craft-adwizard/issues/43))

## 3.4.0 - 2024-05-29

### Added
Expand Down
38 changes: 15 additions & 23 deletions src/models/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,35 +147,27 @@ private function _parseJs(): void
/**
* Process transform
*
* @throws NotFoundHttpException
* @throws InvalidConfigException
* @throws NotFoundHttpException
*/
private function _parseTransform(): void
{
if (is_string($this->image['transform'])) {

// Get pre-defined transform
$transform = clone Craft::$app->getAssetTransforms()->getTransformByHandle($this->image['transform']);

if (!$transform) {
throw new NotFoundHttpException('Transform not found');
// If a transform was specified
if ($this->image['transform']) {

// If transform is a string
if (is_string($this->image['transform'])) {
// Get pre-defined transform
$transform = $this->image['transform'];
// Else if transform is an array
} else if (is_array($this->image['transform'])) {
// Get dynamic transform
$transform = new ImageTransform($this->image['transform']);
} else {
// Invalid transform
throw new NotFoundHttpException('Invalid transform format, please use a string or array.');
}

} else if (is_array($this->image['transform']) && !empty($this->image['transform'])) {

// Get dynamic transform
$transform = new ImageTransform($this->image['transform']);

} else {

// No transform
$transform = false;

}

// If transform exists
if ($transform) {

// Apply transform
$url = $this->asset->getUrl($transform);
$width = $this->asset->getWidth($transform);
Expand Down

0 comments on commit e85cb2f

Please sign in to comment.