/** * {@inheritdoc} */ public function createThumbnail($imagePath, $destination, $maxWidth, $maxHeight, $keepProportions = false, $quality = 90) { if (!$this->mediaService->has($imagePath)) { throw new \Exception("File not found: " . $imagePath); } $content = $this->mediaService->read($imagePath); $image = $this->createImageResource($content, $imagePath); // Determines the width and height of the original image $originalSize = $this->getOriginalImageSize($image); if (empty($maxHeight)) { $maxHeight = $maxWidth; } $newSize = array('width' => $maxWidth, 'height' => $maxHeight); if ($keepProportions) { $newSize = $this->calculateProportionalThumbnailSize($originalSize, $maxWidth, $maxHeight); } $newImage = $this->createNewImage($image, $originalSize, $newSize, $this->getImageExtension($destination)); if ($this->fixGdImageBlur) { $this->fixGdImageBlur($newSize, $newImage); } $this->saveImage($destination, $newImage, $quality); // Removes both the original and the new created image from memory imagedestroy($newImage); imagedestroy($image); }
/** * Deletes all thumbnails from the given media object * * @param Media $media */ public function removeMediaThumbnails(Media $media) { $thumbnails = array_merge(array_values($media->getThumbnailFilePaths()), array_values($media->getThumbnailFilePaths(true))); foreach ($thumbnails as $thumbnail) { $thumbnailPath = $this->rootDir . '/' . $thumbnail; if ($this->mediaService->has($thumbnailPath)) { $this->mediaService->delete($thumbnailPath); } } }
/** * @param string $file */ private function _testRename($file) { $tmpFile = "media/unknown/_phpunit_tmp_rename.json"; $this->mediaService->rename($file, $tmpFile); $this->assertTrue($this->mediaService->has($tmpFile)); $this->assertFalse($this->mediaService->has($file)); $this->_testRead($tmpFile); $this->mediaService->rename($tmpFile, $file); $this->assertTrue($this->mediaService->has($file)); $this->assertFalse($this->mediaService->has($tmpFile)); }
/** * @param MediaServiceInterface $toFileSystem * @param string $path * @param resource $contents * @return boolean */ private function writeStream(MediaServiceInterface $toFileSystem, $path, $contents) { $path = $toFileSystem->encode($path); $dirString = ''; $dirs = explode('/', dirname($path)); foreach ($dirs as $dir) { $dirString .= '/' . $dir; $toFileSystem->createDir($dirString); } $toFileSystem->writeStream($path, $contents); return $toFileSystem->has($path); }