133 private $viewAssetPlaceholderFactory;
145 \
Magento\Framework\View\Asset\Repository $assetRepo,
147 \
Magento\
Catalog\Model\View\Asset\PlaceholderFactory $placeholderFactory =
null 149 $this->_productImageFactory = $productImageFactory;
150 parent::__construct($context);
151 $this->_assetRepo = $assetRepo;
153 $this->viewAssetPlaceholderFactory = $placeholderFactory
155 ->get(\
Magento\
Catalog\Model\View\Asset\PlaceholderFactory::class);
165 $this->_model =
null;
166 $this->_scheduleRotate =
false;
167 $this->_angle =
null;
168 $this->_watermark =
null;
169 $this->_watermarkPosition =
null;
170 $this->_watermarkSize =
null;
171 $this->_watermarkImageOpacity =
null;
172 $this->_product =
null;
173 $this->_imageFile =
null;
174 $this->attributes = [];
190 $this->attributes = array_merge(
191 $this->
getConfigView()->getMediaAttributes(
'Magento_Catalog', self::MEDIA_TYPE_CONFIG_NODE, $imageId),
215 if (!empty($frame)) {
216 $this->
_getModel()->setKeepFrame($frame);
221 if (!empty($constrain)) {
222 $this->
_getModel()->setConstrainOnly($constrain);
227 if (!empty($aspectRatio)) {
228 $this->
_getModel()->setKeepAspectRatio($aspectRatio);
233 if (!empty($transparency)) {
234 $this->
_getModel()->setKeepTransparency($transparency);
239 if (!empty($background)) {
240 $this->
_getModel()->setBackgroundColor($background);
254 $this->scopeConfig->getValue(
255 "design/watermark/{$this->getType()}_image",
260 $this->scopeConfig->getValue(
261 "design/watermark/{$this->getType()}_imageOpacity",
266 $this->scopeConfig->getValue(
267 "design/watermark/{$this->getType()}_position",
272 $this->scopeConfig->getValue(
273 "design/watermark/{$this->getType()}_size",
289 public function resize($width, $height =
null)
291 $this->
_getModel()->setWidth($width)->setHeight($height);
292 $this->_scheduleResize =
true;
304 $this->
_getModel()->setQuality($quality);
319 $this->
_getModel()->setKeepAspectRatio($flag);
355 $this->
_getModel()->setKeepTransparency($flag);
369 $this->
_getModel()->setConstrainOnly($flag);
386 if (!is_array($colorRGB)) {
387 $colorRGB = func_get_args();
389 $this->
_getModel()->setBackgroundColor($colorRGB);
403 $this->_scheduleRotate =
true;
421 )->setWatermarkPosition(
425 )->setWatermarkImageOpacity(
454 $placeholderFullPath =
'Magento_Catalog::images/product/placeholder/' . $placeholder .
'.jpg';
456 $placeholderFullPath = $this->_placeholder
457 ?:
'Magento_Catalog::images/product/placeholder/' . $this->
_getModel()->getDestinationSubdir() .
'.jpg';
459 return $placeholderFullPath;
473 if ($this->_scheduleRotate) {
476 if ($this->_scheduleResize) {
495 $baseFile =
$model->getBaseFile();
514 if (
$model->isBaseFilePlaceholder() ||
$model->isCached()) {
530 }
catch (\Exception $e) {
552 return $this->
_getModel()->getResizedImageInfo();
562 $imageAsset = $this->viewAssetPlaceholderFactory->create(
564 'type' => $placeholder ?: $this->
_getModel()->getDestinationSubdir(),
567 $url = $imageAsset->getUrl();
568 }
catch (\Exception $e) {
569 $this->_logger->critical($e);
570 $url = $this->_urlBuilder->getUrl(
'', [
'_direct' =>
'core/index/notFound']);
582 if (!$this->_model) {
583 $this->_model = $this->_productImageFactory->create();
596 $this->_angle = $angle;
618 $this->_watermark = $watermark;
619 $this->
_getModel()->setWatermarkFile($watermark);
641 $this->_watermarkPosition = $position;
642 $this->
_getModel()->setWatermarkPosition($position);
665 $this->_watermarkSize = $size;
688 $this->_watermarkImageOpacity = $imageOpacity;
689 $this->
_getModel()->setWatermarkImageOpacity($imageOpacity);
700 if ($this->_watermarkImageOpacity) {
704 return $this->
_getModel()->getWatermarkImageOpacity();
737 $this->_imageFile = $file;
759 $size = explode(
'x', strtolower($string));
760 if (
sizeof($size) == 2) {
761 return [
'width' => $size[0] > 0 ? $size[0] :
null,
'height' => $size[1] > 0 ? $size[1] :
null];
773 return $this->
_getModel()->getImageProcessor()->getOriginalWidth();
783 return $this->
_getModel()->getImageProcessor()->getOriginalHeight();
804 if (!$this->configView) {
805 $this->configView = $this->viewConfig->getViewConfig();
848 if ($frame ===
null) {
849 $frame = $this->
getConfigView()->getVarValue(
'Magento_Catalog',
'product_image_white_borders');
862 return $this->attributes[
$name] ??
null;
872 $label = $this->_product->getData($this->
getType() .
'_' .
'label');
874 $label = $this->_product->getName();
__construct(\Magento\Framework\App\Helper\Context $context, \Magento\Catalog\Model\Product\ImageFactory $productImageFactory, \Magento\Framework\View\Asset\Repository $assetRepo, \Magento\Framework\View\ConfigInterface $viewConfig, \Magento\Catalog\Model\View\Asset\PlaceholderFactory $placeholderFactory=null)
getWatermarkImageOpacity()
setWatermarkImageOpacity($imageOpacity)
resize($width, $height=null)
init($product, $imageId, $attributes=[])
setWatermarkPosition($position)
isScheduledActionsAllowed()
getDefaultPlaceholderUrl($placeholder=null)
const MEDIA_TYPE_CONFIG_NODE
getPlaceholder($placeholder=null)
watermark($fileName, $position, $size=null, $imageOpacity=null)
backgroundColor($colorRGB)
if(!isset($_GET['name'])) $name