mirror of
https://git.code.sf.net/p/seeddms/code
synced 2025-02-06 15:14:58 +00:00
add conversion service from jpeg to text based on iptc data
This commit is contained in:
parent
d2eee3345f
commit
aaf7733ab2
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
require_once("inc/inc.ClassConversionServiceExec.php");
|
require_once("inc/inc.ClassConversionServiceExec.php");
|
||||||
require_once("inc/inc.ClassConversionServiceImageToImage.php");
|
require_once("inc/inc.ClassConversionServiceImageToImage.php");
|
||||||
|
require_once("inc/inc.ClassConversionServiceImageToText.php");
|
||||||
require_once("inc/inc.ClassConversionServicePdfToImage.php");
|
require_once("inc/inc.ClassConversionServicePdfToImage.php");
|
||||||
require_once("inc/inc.ClassConversionServiceTextToText.php");
|
require_once("inc/inc.ClassConversionServiceTextToText.php");
|
||||||
|
|
||||||
|
|
75
inc/inc.ClassConversionServiceImageToText.php
Normal file
75
inc/inc.ClassConversionServiceImageToText.php
Normal file
|
@ -0,0 +1,75 @@
|
||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Implementation of conversion service image class
|
||||||
|
*
|
||||||
|
* @category DMS
|
||||||
|
* @package SeedDMS
|
||||||
|
* @license GPL 2
|
||||||
|
* @version @version@
|
||||||
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
||||||
|
* @copyright Copyright (C) 2021 Uwe Steinmann
|
||||||
|
* @version Release: @package_version@
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once("inc/inc.ClassConversionServiceBase.php");
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implementation of conversion service image class
|
||||||
|
*
|
||||||
|
* @category DMS
|
||||||
|
* @package SeedDMS
|
||||||
|
* @author Uwe Steinmann <uwe@steinmann.cx>
|
||||||
|
* @copyright Copyright (C) 2021 Uwe Steinmann
|
||||||
|
* @version Release: @package_version@
|
||||||
|
*/
|
||||||
|
class SeedDMS_ConversionServiceImageToText extends SeedDMS_ConversionServiceBase {
|
||||||
|
/**
|
||||||
|
* timeout
|
||||||
|
*/
|
||||||
|
public $timeout;
|
||||||
|
|
||||||
|
public function __construct($from, $to) { /* {{{ */
|
||||||
|
$this->from = $from;
|
||||||
|
$this->to = $to;
|
||||||
|
} /* }}} */
|
||||||
|
|
||||||
|
public function getInfo() { /* {{{ */
|
||||||
|
return "Convert by extracting iptc data";
|
||||||
|
} /* }}} */
|
||||||
|
|
||||||
|
public function getAdditionalParams() { /* {{{ */
|
||||||
|
return [
|
||||||
|
];
|
||||||
|
} /* }}} */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert a pixel image into text by reading the iptc data
|
||||||
|
*
|
||||||
|
* This method uses getimagesize() to extract the data.
|
||||||
|
*/
|
||||||
|
public function convert($infile, $target = null, $params = array()) { /* {{{ */
|
||||||
|
$start = microtime(true);
|
||||||
|
$imsize = getimagesize($infile, $moreinfo);
|
||||||
|
if(!empty($moreinfo['APP13'])) {
|
||||||
|
$txt = '';
|
||||||
|
$iptcdata = iptcparse($moreinfo['APP13']);
|
||||||
|
foreach(['2#005', '2#015', '2#025', '2#105', '2#080', '2#115', '2#120'] as $key) {
|
||||||
|
if(isset($iptcdata[$key]))
|
||||||
|
$txt .= implode(' ', $iptcdata[$key])."\n";
|
||||||
|
}
|
||||||
|
$end = microtime(true);
|
||||||
|
if($this->logger) {
|
||||||
|
$this->logger->log('Conversion from '.$this->from.' to '.$this->to.' by extracting iptc took '.($end-$start).' sec.', PEAR_LOG_INFO);
|
||||||
|
}
|
||||||
|
if($target) {
|
||||||
|
file_put_contents($target, $txt);
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return $txt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
} /* }}} */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,9 @@ if(extension_loaded('gd') || extension_loaded('imagick')) {
|
||||||
$conversionmgr->addService(new SeedDMS_ConversionServiceImageToImage('image/gif', 'image/png'))->setLogger($logger);
|
$conversionmgr->addService(new SeedDMS_ConversionServiceImageToImage('image/gif', 'image/png'))->setLogger($logger);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$conversionmgr->addService(new SeedDMS_ConversionServiceImageToText('image/jpeg', 'text/plain'))->setLogger($logger);
|
||||||
|
$conversionmgr->addService(new SeedDMS_ConversionServiceImageToText('image/jpg', 'text/plain'))->setLogger($logger);
|
||||||
|
|
||||||
$conversionmgr->addService(new SeedDMS_ConversionServiceTextToText('text/plain', 'text/plain'))->setLogger($logger);
|
$conversionmgr->addService(new SeedDMS_ConversionServiceTextToText('text/plain', 'text/plain'))->setLogger($logger);
|
||||||
|
|
||||||
if(isset($GLOBALS['SEEDDMS_HOOKS']['initConversion'])) {
|
if(isset($GLOBALS['SEEDDMS_HOOKS']['initConversion'])) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user