. ' --server-num=' . $serverNumber;
//cutycapt hangs sometimes - https://sourceforge.net/p/cutycapt/bugs/8/
// we kill it if it does not exit itself
- Executor::runForSomeTime($xvfbcmd . ' ' . $cmd, $maxWaitTime);
+ Executor::runForSomeTime(
+ $xvfbcmd . ' ' . $cmd, $maxWaitTime, 'cutycapt'
+ );
//cutycapt does not report timeouts via exit status
// https://sourceforge.net/p/cutycapt/bugs/11/
. ' -resize ' . $options->values['swidth']
. $crop
. ' ' . escapeshellarg($img->getPath());
- Executor::run($convertcmd);
- //var_dump($convertcmd);die();
+ Executor::run($convertcmd, 'convert');
unlink($tmpPath);
}
/**
* Run a shell command and check exit code.
*
- * @param string $cmd Full command including parameters and options
+ * @param string $cmd Full command including parameters and options
+ * @param string $name Command name for exception
*
* @return void
* @throws \Exception When the exit code is not 0
*/
- public static function run($cmd)
+ public static function run($cmd, $name)
{
exec($cmd . ' 2>&1', $arOutput, $exitcode);
if ($exitcode != 0) {
//FIXME: do something with $arOutput
//echo implode("\n", $arOutput) . "\n";
- throw new \Exception('Error running cutycapt', $exitcode);
+ throw new \Exception('Error running ' . $name, $exitcode);
}
}
* We use the GNU coreutils "timeout" utility instead of the pcntl
* extension since pcntl is disabled on mod_php.
*
- * @param string $cmd Full command including parameters and options
+ * @param string $cmd Full command including parameters and options
+ * @param int $seconds Number of seconds after which the cmd is killed
+ * @param string $name Command name for exception
*
* @return void
* @throws \Exception When the exit code is not 0
*/
- public static function runForSomeTime($cmd, $seconds)
+ public static function runForSomeTime($cmd, $seconds, $name)
{
return static::run(
- 'timeout --signal=9 ' . $seconds . 's ' . $cmd
+ 'timeout --signal=9 ' . $seconds . 's ' . $cmd,
+ $name
);
}
}
--- /dev/null
+<?php
+/**
+ * Part of phancap
+ *
+ * PHP version 5
+ *
+ * @category Tools
+ * @package Phancap
+ * @copyright 2014 Christian Weiske
+ * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3
+ * @link http://cweiske.de/phancap.htm
+ */
+namespace phancap;
+
+/**
+ * Embed meta data into the given file
+ *
+ * @category Tools
+ * @package Phancap
+ * @copyright 2016 Christian Weiske
+ * @license http://www.gnu.org/licenses/agpl.html GNU AGPL v3
+ * @version Release: @package_version@
+ * @link http://cweiske.de/phancap.htm
+ */
+class MetaData
+{
+ /**
+ * Add meta data to the given image
+ *
+ * @param Image $img Image object to render (contains name)
+ * @param Options $options Image rendering options
+ *
+ * @return void
+ * @throws \Exception When something goes wrong
+ */
+ public function embed(Image $img, Options $options)
+ {
+ $modes = array(
+ 'screen' => 'browser window (screen)',
+ 'page' => 'full page height',
+ );
+
+ $title = "Screenshot of " . $options->values['url'];
+ $desc = "Capture options:"
+ . sprintf(
+ ' browser window: %dx%d',
+ $options->values['bwidth'],
+ $options->values['bheight']
+ )
+ . sprintf(
+ ', screenshot size: %dx%d',
+ $options->values['swidth'],
+ $options->values['sheight']
+ )
+ . ', format: ' . $options->values['sformat']
+ . ', mode: ' . $modes[$options->values['smode']];
+
+ Executor::run(
+ 'exiftool'
+ . ' -XMP:title=' . escapeshellarg($title)
+ . ' -XMP:source=' . escapeshellarg($img->getUrl())
+ . ' -XMP:subject=' . escapeshellarg($options->values['url'])
+ . ' -XMP:creator=' . escapeshellarg('phancap')
+ . ' -XMP:description=' . escapeshellarg($desc)
+ . ' ' . escapeshellarg($img->getPath()),
+ 'exiftool'
+ );
+ }
+}
+?>
$adapter->cleanup();
throw $e;
}
+
+ $meta = new MetaData();
+ $meta->embed($img, $options);
}
/**
'err', 'Function "idn_to_ascii" is not available'
);
}
+if (\System::which('exiftool') === false) {
+ $messages[][] = array(
+ 'err', '"exiftool" is not installed'
+ );
+}
$out = <<<HTM
<!DOCTYPE html>