Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Thumbnail.php
Go to the documentation of this file.
1 <?php
8 
10 
12 {
16  protected $resultRawFactory;
17 
23  public function __construct(
24  Action\Context $context,
25  \Magento\Framework\Registry $coreRegistry,
26  \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
27  ) {
28  $this->resultRawFactory = $resultRawFactory;
29  parent::__construct($context, $coreRegistry);
30  }
31 
37  public function execute()
38  {
39  $file = $this->getRequest()->getParam('file');
40  $file = $this->_objectManager->get(\Magento\Cms\Helper\Wysiwyg\Images::class)->idDecode($file);
41  $thumb = $this->getStorage()->resizeOnTheFly($file);
43  $resultRaw = $this->resultRawFactory->create();
44  if ($thumb !== false) {
46  $image = $this->_objectManager->get(\Magento\Framework\Image\AdapterFactory::class)->create();
47  $image->open($thumb);
48  $resultRaw->setHeader('Content-Type', $image->getMimeType());
49  $resultRaw->setContents($image->getImage());
50  return $resultRaw;
51  } else {
52  // todo: generate some placeholder
53  }
54  }
55 }
__construct(Action\Context $context, \Magento\Framework\Registry $coreRegistry, \Magento\Framework\Controller\Result\RawFactory $resultRawFactory)
Definition: Thumbnail.php:23