PHP code example of crd2i / image-bundle

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

    

crd2i / image-bundle example snippets

 php


class ImageController extends Controller
{
    public function userAction($user, $size) {
        $resize = $this->get('image_resizer')
            ->resize(
                $user->getImageFile(), 
                $user->getImageFile($size), 
                new ImageSize($size, $size), 
                ImageResizer::RESIZE_TYPE_CROP
            );
    }
}
 php

// app/autoload.php

$loader->registerNamespaces(array(
    // ...
    'Paradigma'        => __DIR__.'/../vendor/bundles',
));
 php

// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...

        new Paradigma\Bundle\ImageBundle\ParadigmaImageBundle(),
    );
}
 php

...
$resize = $this->get('image_resizer')
    ->resize($filename, $filename_output, new ImageSize($size, $size), ImageResizer::RESIZE_TYPE_AUTO);
....
$resize = $this->get('image_resizer')
    ->resize($filename, $filename_output, new ImageSize($size, $size), ImageResizer::RESIZE_TYPE_CROP);
...
$resize = $this->get('image_resizer')
    ->resize($filename, $filename_output, new ImageSize($size, $size), ImageResizer::RESIZE_TYPE_EXACT);
...
$resize = $this->get('image_resizer')
    ->resize($filename, $filename_output, new ImageSize($size, $size), ImageResizer::RESIZE_TYPE_LANDSCAPE);
...
$resize = $this->get('image_resizer')
    ->resize($filename, $filename_output, new ImageSize($size, $size), ImageResizer::RESIZE_TYPE_PORTRAIT);
...