Esempio n. 1
0
 public function testGenerateSwatchVariations()
 {
     $this->mediaDirectoryMock->expects($this->atLeastOnce())->method('getAbsolutePath')->willReturn('attribute/swatch/e/a/earth.png');
     $image = $this->getMock('\\Magento\\Framework\\Image', ['resize', 'save', 'keepTransparency', 'constrainOnly', 'keepFrame', 'keepAspectRatio', 'backgroundColor', 'quality'], [], '', false);
     $this->imageFactoryMock->expects($this->any())->method('create')->willReturn($image);
     $this->generateImageConfig();
     $image->expects($this->any())->method('resize')->will($this->returnSelf());
     $this->mediaHelperObject->generateSwatchVariations('/e/a/earth.png');
 }
Esempio n. 2
0
 /**
  * Generate swatch thumb and small swatch image
  *
  * @param string $imageUrl
  * @return $this
  */
 public function generateSwatchVariations($imageUrl)
 {
     $absoluteImagePath = $this->mediaDirectory->getAbsolutePath($this->getAttributeSwatchPath($imageUrl));
     foreach ($this->swatchImageTypes as $swatchType) {
         $imageConfig = $this->getImageConfig();
         $swatchNamePath = $this->generateNamePath($imageConfig, $imageUrl, $swatchType);
         $image = $this->imageFactory->create($absoluteImagePath);
         $this->setupImageProperties($image);
         $image->resize($imageConfig[$swatchType]['width'], $imageConfig[$swatchType]['height']);
         $this->setupImageProperties($image, true);
         $image->save($swatchNamePath['path_for_save'], $swatchNamePath['name']);
     }
     return $this;
 }
Esempio n. 3
0
 /**
  * Image Processor
  *
  * @return \Magento\Framework\Image
  */
 public function getImageProcessor()
 {
     if (!$this->processor) {
         $filename = $this->getBaseFile();
         $this->processor = $this->imageFactory->create($filename);
     }
     $this->processor->keepAspectRatio(true);
     $this->processor->keepFrame($this->keepFrame);
     $this->processor->keepTransparency($this->keepTransparency);
     $this->processor->constrainOnly($this->constrainOnly);
     $this->processor->backgroundColor($this->backgroundColor);
     $this->processor->quality($this->quality);
     return $this->processor;
 }
Esempio n. 4
0
 /**
  * Create preview image
  *
  * @param string $imagePath
  * @return $this
  */
 public function createPreviewImage($imagePath)
 {
     list($imageWidth, $imageHeight) = $this->imageParams;
     $image = $this->imageFactory->create($imagePath);
     $image->keepTransparency(true);
     $image->constrainOnly(true);
     $image->keepFrame(true);
     $image->keepAspectRatio(true);
     $image->backgroundColor([255, 255, 255]);
     $image->resize($imageWidth, $imageHeight);
     $imageName = uniqid('preview_image_') . image_type_to_extension($image->getImageType());
     $image->save($this->themeImagePath->getImagePreviewDirectory(), $imageName);
     $this->theme->setPreviewImage($imageName);
     return $this;
 }
 public function getProperDimensionsPictureUrl($facebookId, $pictureUrl)
 {
     $url = $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . '/inchoo/socialconnect/facebook/' . $facebookId;
     $filename = $this->_storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA) . $facebookId;
     $directory = dirname($filename);
     if (!file_exists($directory) || !is_dir($directory)) {
         if (!@mkdir($directory, 0777, true)) {
             return null;
         }
     }
     if (!file_exists($filename) || file_exists($filename) && time() - filemtime($filename) >= 3600) {
         $client = $this->_httpClientFactory->create($pictureUrl);
         $client->setStream();
         $response = $client->request('GET');
         stream_copy_to_stream($response->getStream(), fopen($filename, 'w'));
         $imageObj = $this->_imageFactory->create($filename);
         $imageObj->constrainOnly(true);
         $imageObj->keepAspectRatio(true);
         $imageObj->keepFrame(false);
         $imageObj->resize(150, 150);
         $imageObj->save($filename);
     }
     return $url;
 }
Esempio n. 6
0
 /**
  * @return MagentoImage
  */
 public function getImageProcessor()
 {
     if (!$this->_processor) {
         $filename = $this->getBaseFile() ? $this->_mediaDirectory->getAbsolutePath($this->getBaseFile()) : null;
         $this->_processor = $this->_imageFactory->create($filename);
     }
     $this->_processor->keepAspectRatio($this->_keepAspectRatio);
     $this->_processor->keepFrame($this->_keepFrame);
     $this->_processor->keepTransparency($this->_keepTransparency);
     $this->_processor->constrainOnly($this->_constrainOnly);
     $this->_processor->backgroundColor($this->_backgroundColor);
     $this->_processor->quality($this->_quality);
     return $this->_processor;
 }
Esempio n. 7
0
 public function testGetImageProcessor()
 {
     $imageProcessor = $this->getMockBuilder('\\Magento\\Framework\\Image')->disableOriginalConstructor()->getMock();
     $this->factory->expects($this->once())->method('create')->will($this->returnValue($imageProcessor));
     $this->assertSame($imageProcessor, $this->image->getImageProcessor());
 }