Skip to content

Commit

Permalink
Merge pull request #9 from NicolasBarbey/main
Browse files Browse the repository at this point in the history
add image resize on HeaderHighlights loop
  • Loading branch information
NicolasBarbey authored Jan 30, 2025
2 parents 7081e34 + d6699c8 commit 645e867
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>1.1.6</version>
<version>1.1.7</version>
<authors>
<author>
<name>Loïc MO</name>
Expand Down
49 changes: 48 additions & 1 deletion Loop/HeaderHighlightsLoop.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,19 @@
use Thelia\Core\Template\Loop\Argument\ArgumentCollection;
use Thelia\Model\Lang;
use Thelia\Model\LangQuery;
use Thelia\Type\EnumType;
use Thelia\Type\TypeCollection;


/**
* @method getLocale()
* @method getLangId()
* @method getDisplayType()
* @method getUseTheliaLibrary()
* @method getWidth()
* @method getHeight()
* @method getResizeMode()
* @method getFormat()
*/
class HeaderHighlightsLoop extends BaseI18nLoop implements PropelSearchLoopInterface
{
Expand All @@ -43,9 +49,19 @@ class HeaderHighlightsLoop extends BaseI18nLoop implements PropelSearchLoopInter
protected function getArgDefinitions(): ArgumentCollection
{
return new ArgumentCollection(
Argument::createIntTypeArgument('width'),
Argument::createIntTypeArgument('height'),
Argument::createIntTypeArgument('lang_id', Lang::getDefaultLanguage()->getId()),
Argument::createAlphaNumStringTypeArgument('display_type', null, true),
Argument::createBooleanTypeArgument('use_thelia_library', false)
Argument::createBooleanTypeArgument('use_thelia_library', false),
new Argument(
'resize_mode',
new TypeCollection(
new EnumType(['crop', 'borders', 'none'])
),
'none'
),
Argument::createAlphaNumStringTypeArgument('format')
);
}

Expand All @@ -70,6 +86,37 @@ public function parseResults(LoopResult $loopResult): LoopResult
$imgSourcePath = $headerHighlightsImage->getUploadDir() . DS . $headerHighlightsImage->getFile();

$event = new ImageEvent();

switch ($this->getResizeMode()) {
case 'crop':
$resize_mode = \Thelia\Action\Image::EXACT_RATIO_WITH_CROP;
break;
case 'borders':
$resize_mode = \Thelia\Action\Image::EXACT_RATIO_WITH_BORDERS;
break;
case 'none':
default:
$resize_mode = \Thelia\Action\Image::KEEP_IMAGE_RATIO;
}

$width = $this->getWidth();
$height = $this->getHeight();
$format = $this->getFormat();

if (null !== $width) {
$event->setWidth($width);
}

if (null !== $height) {
$event->setHeight($height);
}

$event->setResizeMode($resize_mode);

if (null !== $format) {
$event->setFormat($format);
}

$event->setSourceFilepath($imgSourcePath)
->setCacheSubdirectory('carousel');

Expand Down

0 comments on commit 645e867

Please sign in to comment.