当我向数据库提交从 pdf 中提取的新图像时,它应该是原始图像的裁剪图像。如果图像已存在于数据库中,则不应插入图像,如果未插入图像,我必须为其生成一个标识值。
识别值也将被插入到与图像相同的表中。
涉及到 key 。表页具有以下标识
pid、qid、pidentifierval、图像
$record = array('pid' => "NULL",
'qid' => $qid,
'pidentifierval' => $pid,
'image' => $crop,
'rotation' => 0);
function newquestionnaire($filename,$desc = "",$type="pngmono"){
global $db;
if ($desc == "") $desc = $filename;
//generate temp file
$tmp = tempnam(TEMPORARY_DIRECTORY, "FORM");
//print "Creating PNG files<br/>";
//use ghostscript to convert to PNG
exec(GS_BIN . " -sDEVICE=$type -r300 -sOutputFile=\"$tmp\"%d.png -dNOPAUSE -dBATCH \"$filename\"");
//add to questionnaire table
//
//create form entry in DB
//
$db->StartTrans();
$sql = "INSERT INTO questionnaires (qid,description,sheets)
VALUES (NULL,'$desc',0)";
$db->Execute($sql);
$qid = $db->Insert_Id();
//Number of imported pages
$pages = 0;
//read pages from 1 to n - stop when n does not exist
$n = 1;
$file = $tmp . $n . ".png";
while (file_exists($file))
{
$data = file_get_contents($file);
$images = split_scanning($data);
unset($image);
unset($data);
foreach($images as $data)
{
//header Cropped Function
// Original image
$filename = $data;
// Get dimensions of the original image
list($current_width, $current_height) = getimagesize($filename);
// The x and y coordinates on the original image where we
// will begin cropping the image
$left = 50;
$top = 50;
// This will be the final size of the image (e.g. how many pixels
// left and down we will be going)
$crop_width = 200;
$crop_height = 200;
// Resample the image
$canvas = imagecreatetruecolor($crop_width, $crop_height);
$current_image = imagecreatefromjpeg($filename);
imagecopy($canvas, $current_image, 0, 0, $left, $top, $current_width, $current_height);
$crop = imagepng($canvas, $filename, 100);
//check for header Cropped Image
我应该在这里做什么功能?
$pid = $pid.$pages;
if ($pid)
{
$pages++;
$record = defaultpage($qid,$pid,$crop);
$db->AutoExecute('pages',$record,'INSERT');
}
else
print T_("INVALID - IGNORING BLANK PAGE");
unset($data);
unset($crop);
我在这里很困惑,我应该如何检查和比较图像是否存在于数据库中。请帮忙
最佳答案
用于裁剪图像
我找到了解决办法
$data = '1.png';
list($current_width, $current_height) = getimagesize($data);
// The x and y co-ordinates on the original image where we will begin cropping the image
$left = 1100;
$top = 30;
// final size of image
$crop_width = 200;
$crop_height = 200;
//Resample the Image
$canvas = imagecreatefromtruecolor($crop_width, $crop_height);
$current_image = imagecreatefrompng($data);
imagecopy($canvas, $current_image, 0, 0, $left, $top, $current_width, $current_height);
imagepng($canvas, $data, 100);
用于比较两个图像
array image_compare(mixed $image1, mixed $image2, int $RTolerance, int $GTolerance, int $BTolerance, int $WarningTolerance, int $ErrorTolerance)
参数 图片1 - 包含图像路径的字符串,或 GD 库已创建的图像资源。这是要比较的第一张图像。 图片2 - 包含第二个图像路径的字符串,或 GD 库已创建的第二个图像的资源。这将是要比较的第二张图像。 RT 容差、GT 容差、BT 容差 (0-255) - 指定抛出标志之前红色、绿色或蓝色(分别) channel 的最大偏差。 警告容差(0-100) - 返回警告之前 channel 差异的百分比。 误差容限(0-100) - 返回错误(标志)之前 channel 差异的百分比。
返回值 将返回一个包含以下信息的数组:
按颜色排列的像素 - 像素数量 * 3(对于每个 R、G 和 B channel )。 像素不合格 - (如果像素变化超出 xTolerance,对于每个红色、绿色和蓝色。其中 x = R/G/B)如果任何 channel 超过阈值,则该数字会递增。 差异百分比 - PixelsOutOfSpec 与 PixelsByColors 比较的差异百分比 警告级别和错误级别 - 如果百分比足够大以触发指定的警告或错误级别。
为了进行比较,我必须工作,我正在考虑使用数组。使用选择查询 我认为,从数据库获取图像,使用 while 循环并在数组中获取结果,调用要存储在变量中的图像的数组键,并在上面的比较函数中使用 if else 条件。你们怎么看?
关于php - 图像裁剪和比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26521834/