Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. private function resize($imageName, $width = null, $height = null)
  2. {
  3. $dynamicPart = $this->generateDynamicPart();
  4.  
  5. $absolutePath =
  6. $this->fileSystem
  7. ->getDirectoryRead(\Magento\Framework\App\Filesystem\DirectoryList::MEDIA)
  8. ->getAbsolutePath('customer/'.$dynamicPart.'/').$imageName.'.'.self::DEFAULT_IMG__EXTENSION;
  9.  
  10. if (!file_exists($absolutePath)) {
  11. $this->log($absolutePath.' does not exist.');
  12. return false;
  13. }
  14.  
  15. $imageResize = $this->imageFactory->create();
  16. $imageResize->open($absolutePath);
  17. $imageResize->constrainOnly(true);
  18. $imageResize->keepTransparency(true);
  19. $imageResize->keepFrame(false);
  20. $imageResize->keepAspectRatio(true);
  21. $imageResize->resize($width, $height);
  22. //destination folder
  23. //$destination = $imageResized;
  24. //save image
  25. $imageResize->save($absolutePath);
  26.  
  27. //$resizedURL = $this->storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA).'resized/'.$width.'/'.$image;
  28. //return 1;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement