/** * Return URL for resized image * * @param \Swissup\Testimonials\Model\Data $testimonial * @return bool|string */ public function resize(\Swissup\Testimonials\Model\Data $testimonial) { if (!$this->getImagePath($testimonial)) { return false; } $width = $this->_configHelper->getImageWidth(); $height = $this->_configHelper->getImageHeight(); $imageFile = $this->getImagePath($testimonial); $cacheDir = $this->getBaseDir() . '/' . 'cache' . '/' . $width; $cacheUrl = $this->getBaseUrl() . '/' . 'cache' . '/' . $width . '/'; $io = $this->_ioFile; $io->checkAndCreateFolder($cacheDir); $io->open(array('path' => $cacheDir)); if ($io->fileExists($imageFile)) { return $cacheUrl . $imageFile; } try { $image = $this->_imageFactory->create($this->getBaseDir() . '/' . $imageFile); $image->resize($width, $height); $image->save($cacheDir . '/' . $imageFile); return $cacheUrl . $imageFile; } catch (\Exception $e) { return false; } }