/** * Generate thumbnails based on the folders in the path * Use * - 128x128 as foldername to generate an image that where the width will * be 128px and the height will be 128px * - 128x as foldername to generate an image that where the width will * be 128px, the height will be calculated based on the aspect ratio. * - x128 as foldername to generate an image that where the width will * be 128px, the height will be calculated based on the aspect ratio. * * @param string $path * @param string $filename */ public function generateThumbnails($path, $filename) { $fs = new Filesystem(); if (!$fs->exists($path . '/source')) { $fs->mkdir($path . '/source'); } $this->moveFile($path . '/source/' . $filename); // generate the thumbnails Model::generateThumbnails($path, $path . '/source/' . $filename); }
/** * This function should be called for the life cycle events @ORM\PostPersist() and @ORM\PostUpdate() */ public function upload() { $file = $this->getFile(); parent::upload(); if (static::GENERATE_THUMBNAILS && $file instanceof UploadedFile) { Model::generateThumbnails(FRONTEND_FILES_PATH . '/' . $this->getTrimmedUploadDir(), $this->getAbsolutePath('source')); } }