PHP code example of digbang / files
1. Go to this page and download the library: Download digbang/files library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
digbang / files example snippets
public function __construct(FileRepository $repository, ImageCurator $curator)
{
$this->repository = $repository;
$this->curator = $curator;
}
public function curateImage(ImageFile $originalImage): ImageFile
{
if (! ($curatedImage = $originalImage->getCurated('SOME_IDENTIFICATION_KEY'))) {
$originalImage->setContentGetter(function () use ($originalImage) {
return $this->repository->getContents($originalImage->getId());
});
$curation = $this->curator
->resize(WIDTH, HEIGHT)
->interlace()
->optimize() //not yet implemented
->buildCuration();
$curatedImage = $originalImage->curate('SOME_IDENTIFICATION_KEY', $curation);
$curatedImage->setContentGetter(function () use ($curatedImage) {
return $this->repository->getContents($curatedImage->getId());
});
$this->repository->persist($curatedImage);
}
return $curatedImage;
}