From: Christian Weiske Date: Tue, 12 Jul 2016 15:21:49 +0000 (+0200) Subject: Embed meta data into generated screenshot file X-Git-Tag: v0.4.0~1 X-Git-Url: https://git.cweiske.de/phancap.git/commitdiff_plain/fc937c3b2eec973b2699e5d2f3a7e6c732bb9eee Embed meta data into generated screenshot file See http://cweiske.de/tagebuch/exif-url.htm --- diff --git a/src/phancap/Adapter/Cutycapt.php b/src/phancap/Adapter/Cutycapt.php index 8d9693c..6c2c41d 100644 --- a/src/phancap/Adapter/Cutycapt.php +++ b/src/phancap/Adapter/Cutycapt.php @@ -115,7 +115,9 @@ class Adapter_Cutycapt . ' --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/ @@ -218,8 +220,7 @@ class Adapter_Cutycapt . ' -resize ' . $options->values['swidth'] . $crop . ' ' . escapeshellarg($img->getPath()); - Executor::run($convertcmd); - //var_dump($convertcmd);die(); + Executor::run($convertcmd, 'convert'); unlink($tmpPath); } diff --git a/src/phancap/Executor.php b/src/phancap/Executor.php index ebe0d60..63931f8 100644 --- a/src/phancap/Executor.php +++ b/src/phancap/Executor.php @@ -29,18 +29,19 @@ class Executor /** * 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); } } @@ -50,15 +51,18 @@ class Executor * 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 ); } } diff --git a/src/phancap/MetaData.php b/src/phancap/MetaData.php new file mode 100644 index 0000000..3cee3a3 --- /dev/null +++ b/src/phancap/MetaData.php @@ -0,0 +1,72 @@ + + * @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 + * @author Christian Weiske + * @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' + ); + } +} +?> diff --git a/src/phancap/Repository.php b/src/phancap/Repository.php index 9e7ad32..b5def74 100644 --- a/src/phancap/Repository.php +++ b/src/phancap/Repository.php @@ -111,6 +111,9 @@ class Repository $adapter->cleanup(); throw $e; } + + $meta = new MetaData(); + $meta->embed($img, $options); } /** diff --git a/www/setup.php b/www/setup.php index 7772bad..78cee18 100644 --- a/www/setup.php +++ b/www/setup.php @@ -87,6 +87,11 @@ if (!function_exists('idn_to_ascii')) { 'err', 'Function "idn_to_ascii" is not available' ); } +if (\System::which('exiftool') === false) { + $messages[][] = array( + 'err', '"exiftool" is not installed' + ); +} $out = <<