PHP code example of chamber-orchestra / image-bundle
1. Go to this page and download the library: Download chamber-orchestra/image-bundle 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/ */
use ChamberOrchestra\ImageBundle\Imagine\Cache\CacheManager;
use ChamberOrchestra\ImageBundle\Service\FilterService;
// Generate a URL (no processing — image processed on first browser hit)
$url = $cacheManager->getBrowserPath('/scores/moonlight_sonata.jpg', 'default', [
'processors' => ['fit' => ['width' => 800, 'height' => 600]],
]);
// Process, cache, and return the resolved URL
$url = $filterService->getProcessedImageUrl('/scores/moonlight_sonata.jpg', 'default', [
'processors' => ['fit' => ['width' => 800, 'height' => 600]],
]);
// Remove all cached variants for a source image
$cacheManager->remove('/scores/moonlight_sonata.jpg');
use ChamberOrchestra\FileBundle\Model\File;
use ChamberOrchestra\ImageBundle\Serializer\Attribute\ImageFilter;
class ConcertView
{
public string $title = 'Moonlight Sonata';
#[ImageFilter(filter: 'fill', width: 300, height: 300)]
public ?File $coverArt = null;
}
use ChamberOrchestra\ImageBundle\Binary\Loader\LoaderInterface;
class MyLoader implements LoaderInterface
{
public function find(string $path): BinaryInterface|string { /* ... */ }
public function getName(): string { return 'my_loader'; }
}
// In your bundle's build() method:
$extension->addLoaderFactory(new MyLoaderFactory());
use ChamberOrchestra\ImageBundle\Imagine\Cache\Resolver\CacheResolver;
use Symfony\Component\Cache\Adapter\RedisAdapter;
$resolver = new CacheResolver(
new RedisAdapter($redis),
$innerWebPathResolver,
['lifetime' => 3600]
);