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