private function generateFileThumb(MediaInterface $media)
    {
        $extension   = $media->guessExtension();
        $thumbPath   = sprintf('/%s/%s.jpg', $this->thumbsDirectory, $extension);
        $destination = $this->webRootDirectory . $thumbPath;

        if (file_exists($destination)) {
            return $thumbPath;
        }

        $backgroundColor = MediaTypes::getColor($media->getType());

        $iconPath = sprintf('%s/%s.png', $this->iconsSourcePath, $extension);
        if (! file_exists($iconPath)) {
            $iconPath = $this->iconsSourcePath.'/default.png';
        }

        $this->checkDir(dirname($destination));
        try {
            $palette = new RGB();
            $thumb = $this->imagine->create(new Box(120, 90), $palette->color($backgroundColor));

            $icon = $this->imagine->open($iconPath);
            $iconSize = $icon->getSize();
            $start = new Point(120/2 - $iconSize->getWidth()/2, 90/2 - $iconSize->getHeight()/2);

            $thumb->paste($icon, $start);
            $thumb->save($destination);

            return $thumbPath;
        } catch (ImagineException $e) {
            // Image thumb generation failed
        }

        return null;
    }
private function generateFileThumb(MediaInterface $media)
    {
        $extension   = $media->guessExtension();
        $thumbPath   = sprintf('/%s/%s.jpg', $this->thumbsDirectory, $extension);
        $destination = $this->webRootDirectory . $thumbPath;

        if (file_exists($destination)) {
            return $thumbPath;
        }

        $backgroundColor = MediaTypes::getColor($media->getType());

        $iconPath = sprintf('%s/%s.png', $this->iconsSourcePath, $extension);
        if (! file_exists($iconPath)) {
            $iconPath = $this->iconsSourcePath.'/default.png';
        }

        $this->checkDir(dirname($destination));
        try {
            $palette = new RGB();
            $thumb = $this->imagine->create(new Box(120, 90), $palette->color($backgroundColor));

            $icon = $this->imagine->open($iconPath);
            $iconSize = $icon->getSize();
            $start = new Point(120/2 - $iconSize->getWidth()/2, 90/2 - $iconSize->getHeight()/2);

            $thumb->paste($icon, $start);
            $thumb->save($destination);

            return $thumbPath;
        } catch (ImagineException $e) {
            // Image thumb generation failed
        }

        return null;
    }
private function generateFileThumb ( MediaInterface $ media ) { $ extension = $ media -> guessExtension ( ) ; $ thumbPath = sprintf ( '/%s/%s.jpg' , $ this -> thumbsDirectory , $ extension ) ; $ destination = $ this -> webRootDirectory . $ thumbPath ; if ( file_exists ( $ destination ) ) { return $ thumbPath ; } $ backgroundColor = MediaTypes :: getColor ( $ media -> getType ( ) ) ; $ iconPath = sprintf ( '%s/%s.png' , $ this -> iconsSourcePath , $ extension ) ; if ( ! file_exists ( $ iconPath ) ) { $ iconPath = $ this -> iconsSourcePath . '/default.png' ; } $ this -> checkDir ( dirname ( $ destination ) ) ; try { $ palette = new RGB ( ) ; $ thumb = $ this -> imagine -> create ( new Box ( 120 , 90 ) , $ palette -> color ( $ backgroundColor ) ) ; $ icon = $ this -> imagine -> open ( $ iconPath ) ; $ iconSize = $ icon -> getSize ( ) ; $ start = new Point ( 120 / 2 - $ iconSize -> getWidth ( ) / 2 , 90 / 2 - $ iconSize -> getHeight ( ) / 2 ) ; $ thumb -> paste ( $ icon , $ start ) ; $ thumb -> save ( $ destination ) ; return $ thumbPath ; } catch ( ImagineException $ e ) { // Image thumb generation failed } return null ; }
Generates thumb for non-image elements.

@param MediaInterface $media
@return null|string
Generates thumb for non - image elements .