<?php
$res=json_decode(file_get_contents("res.json")); // прочитаем json
$source = imagecreatefromjpeg ("pdfs/11-1.jpg");
$pink = imagecolorallocate($source, 255, 105, 180);
$white = imagecolorallocate($source, 255, 255, 255);
$green = imagecolorallocate($source, 132, 135, 28);
$blue = imagecolorallocate($source, 0, 0, 255);
// размечаю блоки
$bl=0;
foreach ($res->result->textAnnotation->blocks as $block) {
$kof=1.5;
$points=[];
$points[]=$block->boundingBox->vertices[0]->x*$kof;
$points[]=$block->boundingBox->vertices[0]->y*$kof;
$points[]=$block->boundingBox->vertices[1]->x*$kof;
$points[]=$block->boundingBox->vertices[1]->y*$kof;
$points[]=$block->boundingBox->vertices[2]->x*$kof;
$points[]=$block->boundingBox->vertices[2]->y*$kof;
$points[]=$block->boundingBox->vertices[3]->x*$kof;
$points[]=$block->boundingBox->vertices[3]->y*$kof;
$points[]=$block->boundingBox->vertices[0]->x*$kof;
$points[]=$block->boundingBox->vertices[0]->y*$kof;
imagepolygon($source,$points,$green);
imagettftext($source,20,0,$points[0],$points[1],$green,"/usr/share/fonts/truetype/r7-office/ext/PTS55F.ttf",$bl);
$bl++;
};
//размечаю таблицы
$bl=0;
foreach ($res->result->textAnnotation->tables as $table) {
$kof=2.1;
$offset_x=110;
$offset_y=10;
$points=[];
$points[]=$table->boundingBox->vertices[0]->x*$kof+$offset_x;
$points[]=$table->boundingBox->vertices[0]->y*$kof+$offset_y;
$points[]=$table->boundingBox->vertices[1]->x*$kof+$offset_x;
$points[]=$table->boundingBox->vertices[1]->y*$kof+$offset_y;
$points[]=$table->boundingBox->vertices[2]->x*$kof+$offset_x;
$points[]=$table->boundingBox->vertices[2]->y*$kof+$offset_y;
$points[]=$table->boundingBox->vertices[3]->x*$kof+$offset_x;
$points[]=$table->boundingBox->vertices[3]->y*$kof+$offset_y;
$points[]=$table->boundingBox->vertices[0]->x*$kof+$offset_x;
$points[]=$table->boundingBox->vertices[0]->y*$kof+$offset_y;
imagepolygon($source,$points,$blue);
imagettftext($source,20,0,$points[0],$points[1],$blue,"/usr/share/fonts/truetype/r7-office/ext/PTS55F.ttf",$bl);
$bl++;
}
imagejpeg($source, 'out.jpg');