6 declare(strict_types=1);
22 private $defaultQuality = 80;
27 private $defaultBackground = [255, 255, 255];
32 private $defaultAngle =
null;
37 private $defaultKeepAspectRatio =
true;
42 private $defaultKeepTransparency =
true;
47 private $defaultConstrainOnly =
true;
67 $this->scopeConfig = $scopeConfig;
68 $this->viewConfig = $viewConfig;
77 public function build(array $imageArguments): array
80 'image_type' => $imageArguments[
'type'] ??
null,
81 'image_height' => $imageArguments[
'height'] ??
null,
82 'image_width' => $imageArguments[
'width'] ??
null,
85 $overwritten = $this->overwriteDefaultValues($imageArguments);
86 $watermark = isset($miscParams[
'image_type']) ? $this->getWatermark($miscParams[
'image_type']) : [];
88 return array_merge($miscParams, $overwritten, $watermark);
95 private function overwriteDefaultValues(array $imageArguments): array
97 $frame = $imageArguments[
'frame'] ?? $this->hasDefaultFrame();
98 $constrain = $imageArguments[
'constrain'] ?? $this->defaultConstrainOnly;
99 $aspectRatio = $imageArguments[
'aspect_ratio'] ?? $this->defaultKeepAspectRatio;
100 $transparency = $imageArguments[
'transparency'] ?? $this->defaultKeepTransparency;
101 $background = $imageArguments[
'background'] ?? $this->defaultBackground;
102 $angle = $imageArguments[
'angle'] ?? $this->defaultAngle;
105 'background' => (array) $background,
107 'quality' => $this->defaultQuality,
108 'keep_aspect_ratio' => (
bool) $aspectRatio,
109 'keep_frame' => (bool) $frame,
110 'keep_transparency' => (
bool) $transparency,
111 'constrain_only' => (bool) $constrain,
119 private function getWatermark(
string $type): array
121 $file = $this->scopeConfig->getValue(
122 "design/watermark/{$type}_image",
123 ScopeInterface::SCOPE_STORE
127 $size = $this->scopeConfig->getValue(
128 "design/watermark/{$type}_size",
129 ScopeInterface::SCOPE_STORE
131 $opacity = $this->scopeConfig->getValue(
132 "design/watermark/{$type}_imageOpacity",
133 ScopeInterface::SCOPE_STORE
135 $position = $this->scopeConfig->getValue(
136 "design/watermark/{$type}_position",
137 ScopeInterface::SCOPE_STORE
139 $width = !empty($size[
'width']) ? $size[
'width'] :
null;
140 $height = !empty($size[
'height']) ? $size[
'height'] :
null;
143 'watermark_file' => $file,
144 'watermark_image_opacity' => $opacity,
145 'watermark_position' => $position,
146 'watermark_width' => $width,
147 'watermark_height' => $height
158 private function hasDefaultFrame(): bool
160 return (
bool) $this->viewConfig->getViewConfig()->getVarValue(
162 'product_image_white_borders' __construct(ScopeConfigInterface $scopeConfig, ConfigInterface $viewConfig)
build(array $imageArguments)