/** * Constructor * * @param string $path file path to a PDF. */ public function __construct($path, $options = array()) { # Make sure it exists and is readable. if (!is_file($path) || !is_readable($path)) { throw new \Exception('File does not exist, or could not be read.'); } # Make sure it's a PDF. $mtype = Mime::mime($path); if ($mtype != 'application/pdf' && $mtype != 'application/x-pdf') { throw new \Exception('File is not a PDF.'); } $this->path = $path; $this->pathinfo = pathinfo($path); $this->info = $this->getInfo(); $this->npages = $this->info['Pages']; $this->options = array_merge($this->defaults, $options); if ($this->options['verbose']) { $this->verbose = true; } if (is_null($this->options['basename'])) { $this->options['basename'] = $this->pathinfo['filename']; } if ($this->options['resolution'] == 0) { $this->options['resolution'] = $this->getResolution(); } }
/** * Constructor * * Parses arguments, looks for a command, and hands off command * options to another Relic library function. */ public function __construct() { $this->_parseArgs(); if (array_key_exists($this->command, $this->commands)) { $args = $this->_parseOpts($this->commands[$this->command]['options'], $this->commands[$this->command]['params']); switch ($this->command) { case 'thumb': Image::thumbnail($args['params']['image'], $args['params']['dst'], $args['options']); break; case 'split': PDF::split($args); break; case 'metadata': $mime = Mime::mime($args['params']['file']); if (in_array($mime, array('image/jpg', 'image/jpeg', 'image/tiff'))) { $image = new Image($args['params']['file']); $this->prettyPrint($image->exif()); } else { if ($mime == 'application/pdf') { $pdf = new PDF($args['params']['file']); $this->prettyPrint($pdf->info); } } break; case 'mime': Mime::printMime($args['params']['file']); break; } } else { $this->_usage(false, 'Unknown command.'); exit(1); } }
/** * Create a preview image given a source image. * * @param string $src * @param string $dst * @return bool */ public static function preview($src, $dst, $options = array()) { if (!is_readable($src)) { return false; } if (Mime::mime($src) == 'application/pdf') { $src .= '[0]'; } $image = new static($src); $image->format('jpeg'); $image->scale(700, 700); return $image->save($dst); }