/** * Get current Image model * * @return \Magento\Catalog\Model\Product\Image */ protected function _getModel() { if (!$this->_model) { $this->_model = $this->_productImageFactory->create(); } return $this->_model; }
/** * Initialize Helper to work with Image * * @param \Magento\Catalog\Model\Product $product * @param string $attributeName * @param string|null $imageFile * @return $this */ public function init(\Magento\Catalog\Model\Product $product, $attributeName, $imageFile = null) { $this->_reset(); $this->_setModel($this->_productImageFactory->create()); $this->_getModel()->setDestinationSubdir($attributeName); $this->setProduct($product); $this->setWatermark($this->scopeConfig->getValue("design/watermark/{$this->_getModel()->getDestinationSubdir()}_image", \Magento\Store\Model\ScopeInterface::SCOPE_STORE)); $this->setWatermarkImageOpacity($this->scopeConfig->getValue("design/watermark/{$this->_getModel()->getDestinationSubdir()}_imageOpacity", \Magento\Store\Model\ScopeInterface::SCOPE_STORE)); $this->setWatermarkPosition($this->scopeConfig->getValue("design/watermark/{$this->_getModel()->getDestinationSubdir()}_position", \Magento\Store\Model\ScopeInterface::SCOPE_STORE)); $this->setWatermarkSize($this->scopeConfig->getValue("design/watermark/{$this->_getModel()->getDestinationSubdir()}_size", \Magento\Store\Model\ScopeInterface::SCOPE_STORE)); if ($imageFile) { $this->setImageFile($imageFile); } else { // add for work original size $this->_getModel()->setBaseFile($this->getProduct()->getData($this->_getModel()->getDestinationSubdir())); } return $this; }