src/Sulu/Bundle/MediaBundle/Media/ImageConverter/MediaImageExtractor.php
private function convertPdfToImage($resource)
    {
        $temporaryFilePath = $this->createTemporaryFile($resource);

        $command = $this->ghostScriptPath .
            ' -dNOPAUSE -sDEVICE=jpeg -dFirstPage=1 -dLastPage=1 -sOutputFile=' . $temporaryFilePath . ' ' .
            '-dJPEGQ=100 -r300x300 -q ' . $temporaryFilePath . ' -c quit 2> /dev/null';

        shell_exec($command);
        $output = file_get_contents($temporaryFilePath);
        unlink($temporaryFilePath);

        if (!$output) {
            throw new GhostScriptNotFoundException(
                'Ghostscript was not found at "' .
                $this->ghostScriptPath .
                '"'
            );
        }

        return $this->createTemporaryResource($output);
    }
private function convertPdfToImage($resource)
    {
        $temporaryFilePath = $this->createTemporaryFile($resource);

        $command = $this->ghostScriptPath .
            ' -dNOPAUSE -sDEVICE=jpeg -dFirstPage=1 -dLastPage=1 -sOutputFile=' . $temporaryFilePath . ' ' .
            '-dJPEGQ=100 -r300x300 -q ' . $temporaryFilePath . ' -c quit 2> /dev/null';

        shell_exec($command);
        $output = file_get_contents($temporaryFilePath);
        unlink($temporaryFilePath);

        if (!$output) {
            throw new GhostScriptNotFoundException(
                'Ghostscript was not found at "' .
                $this->ghostScriptPath .
                '"'
            );
        }

        return $this->createTemporaryResource($output);
    }
private function convertPdfToImage ( $ resource ) { $ temporaryFilePath = $ this -> createTemporaryFile ( $ resource ) ; $ command = $ this -> ghostScriptPath . ' -dNOPAUSE -sDEVICE=jpeg -dFirstPage=1 -dLastPage=1 -sOutputFile=' . $ temporaryFilePath . ' ' . '-dJPEGQ=100 -r300x300 -q ' . $ temporaryFilePath . ' -c quit 2> /dev/null' ; shell_exec ( $ command ) ; $ output = file_get_contents ( $ temporaryFilePath ) ; unlink ( $ temporaryFilePath ) ; if ( ! $ output ) { throw new GhostScriptNotFoundException ( 'Ghostscript was not found at "' . $ this -> ghostScriptPath . '"' ) ; } return $ this -> createTemporaryResource ( $ output ) ; }
Converts the first page of pdf to an image using ghostscript.

@param resource $resource

@return resource

@throws GhostScriptNotFoundException
Converts the first page of pdf to an image using ghostscript .