src/Kunstmaan/MediaBundle/Helper/Transformer/PdfTransformer.php
public function apply($absolutePath)
    {
        $info = pathinfo($absolutePath);

        if (isset($info['extension']) && false !== strpos(strtolower($info['extension']), 'pdf') && file_exists($absolutePath)) {
            // If it doesn't exist yet, extract the first page of the PDF
            $previewFilename = $this->getPreviewFilename($absolutePath);
            if (!file_exists($previewFilename)) {
                $this->imagick->readImage($absolutePath . '[0]');
                $this->imagick->setImageFormat('jpg');
                $this->imagick->mergeImageLayers(\Imagick::LAYERMETHOD_FLATTEN);
                $this->imagick->writeImage($previewFilename);
                $this->imagick->clear();
            }

            $absolutePath = $previewFilename;
        }

        return $absolutePath;
    }
public function apply($absolutePath)
    {
        $info = pathinfo($absolutePath);

        if (isset($info['extension']) && false !== strpos(strtolower($info['extension']), 'pdf') && file_exists($absolutePath)) {
            // If it doesn't exist yet, extract the first page of the PDF
            $previewFilename = $this->getPreviewFilename($absolutePath);
            if (!file_exists($previewFilename)) {
                $this->imagick->readImage($absolutePath . '[0]');
                $this->imagick->setImageFormat('jpg');
                $this->imagick->mergeImageLayers(\Imagick::LAYERMETHOD_FLATTEN);
                $this->imagick->writeImage($previewFilename);
                $this->imagick->clear();
            }

            $absolutePath = $previewFilename;
        }

        return $absolutePath;
    }
public function apply ( $ absolutePath ) { $ info = pathinfo ( $ absolutePath ) ; if ( isset ( $ info [ 'extension' ] ) && false !== strpos ( strtolower ( $ info [ 'extension' ] ) , 'pdf' ) && file_exists ( $ absolutePath ) ) { // If it doesn't exist yet, extract the first page of the PDF $ previewFilename = $ this -> getPreviewFilename ( $ absolutePath ) ; if ( ! file_exists ( $ previewFilename ) ) { $ this -> imagick -> readImage ( $ absolutePath . '[0]' ) ; $ this -> imagick -> setImageFormat ( 'jpg' ) ; $ this -> imagick -> mergeImageLayers ( \ Imagick :: LAYERMETHOD_FLATTEN ) ; $ this -> imagick -> writeImage ( $ previewFilename ) ; $ this -> imagick -> clear ( ) ; } $ absolutePath = $ previewFilename ; } return $ absolutePath ; }
Apply the transformer on the absolute path and return an altered version of it.

@param string $absolutePath

@return string|false
Apply the transformer on the absolute path and return an altered version of it .