This commit is contained in:
xdrm-brackets 2017-09-13 17:24:07 +02:00
parent 84ee33f718
commit 7fa39e90d3
1 changed files with 40 additions and 25 deletions

View File

@ -228,7 +228,7 @@
/* (3) Exctracts an event
/* (3) Exctracts an event using OCR
*
* @uid<String> Image uid
* @start<Array> Start rect (x, y)
@ -236,37 +236,52 @@
*
---------------------------------------------------------*/
public function extractEvent($uid, $start=null, $stop=null){
$link = __ROOT__."/tmp/$uid.jpeg";
/* [1] Get the right clip
=========================================================*/
/* (1) Create clipped copy */
$clip = \imagecreatetruecolor($stop[0]-$start[0], $stop[1]-$start[1]);
=========================================================*/ {
/* (1) Create clipped copy */
$clip = \imagecreatetruecolor($stop[0]-$start[0], $stop[1]-$start[1]);
$copied = \imagecopyresized(
$clip, // destin img
$this->img_res, // source img
0, // dest x
0, // dest y
$start[0], // src x
$start[1], // src y
$stop[0]-$start[0], // dest w
$stop[1]-$start[1], // dest h
$stop[0]-$start[0], // src w
$stop[1]-$start[1] // src h
);
$copied = \imagecopyresized(
$clip, // destin img
$this->img_res, // source img
0, // dest x
0, // dest y
$start[0], // src x
$start[1], // src y
$stop[0]-$start[0], // dest w
$stop[1]-$start[1], // dest h
$stop[0]-$start[0], // src w
$stop[1]-$start[1] // src h
);
/* (2) Manage copy error */
if( !$copied )
throw new \Exception("Cannot clip image");
/* (2) Manage copy error */
if( !$copied )
throw new \Exception("Cannot clip image");
/* (3) Save to file */
\imagesavealpha($clip, true);
if( !\imagejpeg($clip, __ROOT__."/tmp/$uid.jpeg") )
throw new \Exception("Cannot save image");
/* (3) Save to file */
\imagesavealpha($clip, true);
if( !\imagejpeg($clip, $link) )
throw new \Exception("Cannot save image");
}
/* [2] Process OCR
=========================================================*/
// TODO:
=========================================================*/ {
/* (1) Creates a Tesseract (OCR) instance */
// $ocr = new Tesseract($link);
/* (2) Reads from file */
// $ocr->read();
}
}