PHP code example of rvdlee / zf-image-resizer

1. Go to this page and download the library: Download rvdlee/zf-image-resizer 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/ */

    

rvdlee / zf-image-resizer example snippets


# ... config use statements

return [
    'rvdlee' => [
        'zf-image-resizer'   => [
            'adapter'         => ImageMagick::class,
            'validator-chain' => [
                ['name' => IsImage::class],
            ],
        ],
    ],
]; 

$this->add(
    [
        'type'       => FileInput::class,
        'name'       => 'avatar',
        'mageResizer::class,
                'options' => [
                    'mode'        => Image::ONLY_CROP_MODUS,
                    'crop_mode'   => Image::CENTERED_CROP,
                    'crop_width'  => 100,
                    'crop_height' => 100,
                ],
            ],
        ],
        'validators' => [
            # ... Validators
        ],
    ]
);

class SomeFactory implements FactoryInterface
{
    public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
    {
        /** @var ImageResizerService $imageOptimiserService */
        $imageResizerService = $container->get(ImageResizerService::class);

        # or... provide your own LoggerInterface

        /** @var Logger $logger */
        $logger = $container->get(Logger::class);
        /** @var Stream $writer */
        $logger->addWriter(new Stream('php://output'));
        /** @var ImageResizerService $imageOptimiserService */
        $imageResizerService = $container->build(ImageResizerService::class, ['logger' => $logger]);

        # ... other factory stuff
    }
}

/** @var array|WriterInterface[] $writers */
$writers = $imageResizerService->getLogger()->getWriters()->toArray();
/** @var Zend\Log\Writer\Mock $mockWriter */
$mockWriter = $writers[0];
/** @var array $events */
$events = $mockWriter->events;