/** * Config must provide the following keys: * - server: ActiveMQ server to connect to. Messages go into an in-memory * queue if the server name is "__test__". * @return: null, as the rendition is generated asynchronously. */ public static function render($source, $target, $assetFile, $config) { $bucket = $config['_bucket']; $queue = $config['queue']; $message = array('asset' => $assetFile, 'config' => $config, 'bucket' => $bucket, 'tstamp' => time()); if ($queue == '__test__') { array_push(self::$messages, $message); } else { $log = new api_log(); $log->debug("Queueing message: {$assetFile}"); $conn = new Amazon_SQS_Client($config['access_id'], $config['secret_key']); $response = $conn->sendMessage(array('QueueName' => $queue, 'MessageBody' => json_encode($message))); $result = $response->getSendMessageResult(); $log->debug("Queued message ID %s for asset file %s", $result->getMessageId(), $assetFile); } }
/** * Convert a PDF/EPS to JPG/PNG. * * @param $from: File path to the original file. * @param $to: File path where the new file should be saved. * @param $format: Format to convert to. */ protected static function convert($from, $to, $format) { $cmd = binarypool_config::getUtilityPath('pdfconverter'); $cmd .= ' -f ' . $format; $cmd .= ' ' . escapeshellarg($from) . ' ' . escapeshellarg($to); $log = new api_log(); $log->debug("Rendering PDF with command: {$cmd}"); shell_exec($cmd); }
protected static function convert($from, $to) { $cmd = binarypool_config::getUtilityPath('convert'); $cmd .= ' -density 288 -resize 220 +antialias'; # Make sure all output images are in RGB. This handles incoming CMYK # images which some browsers can't display. $cmd .= ' -colorspace RGB -trim '; $cmd .= escapeshellarg($from) . ' ' . escapeshellarg($to); $log = new api_log(); $log->debug("Converting PDF/EPS image using command: {$cmd}"); shell_exec($cmd); }
/** * Convert a picture to a different format and/or resize it. * * @param $from: File path to the original file. * @param $to: File path where the new file should be saved. * @param $mime: MIME type of the original image. * @param $maxWidth: Maximum width of the new image. No resizing * is done if this is empty. Can be used without * specifying maxHeight. * @param $maxHeight: Maximum height of the new image. Must be * used together with $maxWidth. */ protected static function convert($from, $to, $mime, $maxWidth = '', $maxHeight = '') { $cmd = binarypool_config::getUtilityPath('convert'); # Make sure all output images are in RGB. This handles incoming CMYK # images which some browsers can't display. $cmd .= ' -colorspace RGB'; switch ($mime) { case 'image/pdf': case 'application/pdf': $cmd .= ' -trim'; break; case 'image/gif': break; default: $cmd .= ' -flatten'; break; } if ($maxWidth != '') { $scale = intval($maxWidth); if ($maxHeight != '') { $scale .= 'x' . intval($maxHeight); # Don't enlarge if the size is already smaller than resized version $scale .= '>'; } $cmd .= ' -resize ' . escapeshellarg($scale) . ''; } if ($mime == 'image/jpeg') { # Sharpen image $cmd .= ' -unsharp 0.5x1'; } $cmd = $cmd . ' ' . escapeshellarg($from) . ' ' . escapeshellarg($to); $log = new api_log(); $log->debug("Resizing image using command: {$cmd}"); shell_exec($cmd); }