123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- <?php
- /**
- * Copyright © 2015-2017 Ihor Vansach (ihor@magefan.com). All rights reserved.
- * See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
- *
- * Glory to Ukraine! Glory to the heroes!
- */
- namespace Magefan\Blog\Model;
- use Magefan\Blog\Model\Url;
- use Magefan\Blog\Helper\Image as ImageHelper;
- /**
- * Image model
- *
- * @method string getFile()
- * @method $this setFile(string $value)
- */
- class Image extends \Magento\Framework\DataObject
- {
- /**
- * @var \Magefan\Blog\Model\Url
- */
- protected $url;
- /**
- * @var \Magefan\Blog\Helper\Image
- */
- protected $imageHelper;
- /**
- * Initialize dependencies.
- *
- * @param \Magento\Framework\Model\Context $context
- * @param \Magento\Framework\Registry $registry
- * @param \Magefan\Blog\Model\Url $url
- * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
- * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
- * @param array $data
- */
- public function __construct(
- Url $url,
- ImageHelper $imageHelper,
- array $data = []
- ) {
- parent::__construct($data);
- $this->url = $url;
- $this->imageHelper = $imageHelper;
- }
- /**
- * Retrieve image url
- * @return string
- */
- public function getUrl()
- {
- if ($this->getFile()) {
- return $this->url->getMediaUrl($this->getFile());
- }
- return null;
- }
- /**
- * Resize image
- * @param int $width
- * @param int $height
- * @return string
- */
- public function resize($width, $height = null)
- {
- return $this->imageHelper->init($this->getFile())
- ->resize($width, $height);
- }
- /**
- * Retrieve image url
- * @return string
- */
- public function __toString()
- {
- return $this->getUrl();
- }
- }
|