Created
March 11, 2015 08:40
-
-
Save slashfan/b68e58fe889fafeeaa45 to your computer and use it in GitHub Desktop.
Basic ImageExtractor PHP Class - Extract first page of a PDF file to an image (jpg or png) using Imagick PHP extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Acme\Util; | |
/** | |
* ImageExtractor | |
*/ | |
class ImageExtractor | |
{ | |
const FORMAT_JPG = 'jpg'; | |
const FORMAT_PNG = 'png'; | |
/** | |
* @param string $source source filepath | |
* @param string $destination destination filepath | |
* @param string $format destination format | |
* | |
* @return bool | |
*/ | |
public static function extract($source, $destination, $format = self::FORMAT_JPG) | |
{ | |
if (!extension_loaded('Imagick')) { | |
return false; | |
} | |
$imagick = new \Imagick($source . '[0]'); | |
$imagick->setFormat($format); | |
return $imagick->writeImage($destination); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment