Php 通过gimp批处理模式应用图像透视功能

Php 通过gimp批处理模式应用图像透视功能,php,image,gimp,Php,Image,Gimp,我有两张照片 第一个是报纸,第二个是一个人的脸 我正在写一个php程序,目的是修复一个人在报纸上的脸。以下是报纸图片 我通过api获得perosn的个人资料图片,有时比白色占位符大一点,有时比白色占位符小一点,但无法控制 我在Gimp 2.8中测试了图像透视功能,并将轮廓图片完美地固定在白色的位置保持架中 我曾经尝试过Imagick类的方法和方法来旋转和轮廓图片,并在报纸上修复它,但问题是扭曲图片的方法 随机增加配置文件的大小 我也尝试了类,使用了旋转和覆盖的方法来实现这个目标,但面临着同样的问

我有两张照片

第一个是报纸,第二个是一个人的脸

我正在写一个php程序,目的是修复一个人在报纸上的脸。以下是报纸图片

我通过api获得perosn的个人资料图片,有时比白色占位符大一点,有时比白色占位符小一点,但无法控制

我在Gimp 2.8中测试了图像透视功能,并将轮廓图片完美地固定在白色的位置保持架中

我曾经尝试过Imagick类的方法和方法来旋转和轮廓图片,并在报纸上修复它,但问题是扭曲图片的方法 随机增加配置文件的大小

我也尝试了类,使用了旋转和覆盖的方法来实现这个目标,但面临着同样的问题,profile pic的大小会增加,最终不得不处理一些硬编码

在以上两种方法中,我需要硬编码开始位置,但它应该始终位于位置保持器的左上角

有100多张带有图像定位器的报纸图片,定位器的位置从一张图片到另一张图片会发生变化,它们基本上是一个小视频的帧

现在的问题是,是否可以通过gimp批处理模式执行此操作??然后想写脚本来完成这个任务

我曾尝试在线查找文档,以了解如何在gimp批处理中为图像透视功能编写脚本,但并没有达到完美的位置:

请据此指导

如果Ubuntu上有任何其他图像处理工具,可以方便地编写脚本并完成所需的操作,那么我也可以使用该图像处理工具/软件

代码


提前感谢。

为您的问题添加代码,这是您迄今为止尝试过的问题。通过查看代码,可能有人会相应地指导您。我使用了Imagick Library,它可能是
<?php
/* read co ordinates as csv from file and stored in $co_ordinates */
$XYaxies = explode(",", $co_ordinates[$i]);

          $x1=(int)$XYaxies[0];
          $y1=(int)$XYaxies[1];
          $x2=(int)$XYaxies[2];
          $y2=(int)$XYaxies[3];
          $x3=(int)$XYaxies[4];
          $y3=(int)$XYaxies[5];
          $x4=(int)$XYaxies[6];
          $y4=(int)$XYaxies[7];

/* these are coordinates of white image place holder */
/* x1,y1 top left corner */
/* x2,y2 top right corner */
/* x3,y3 bottom right corner */
/* x4,y4 bottom left corner */

$profile_pic_path = "face.png";
$frame_path="frame1.png";
$target_frame_path = "result_framr1.png";

$im = new Imagick($profile_pic_path);

$im->setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT);
$im->setImageMatte(true);
$profile_x1=$x1; $profile_x4=$x1;
$profile_x2=$x1+$profile_pic_width;
$profile_x3=$profile_x2;

$profile_y1=$y1; $profile_y2=$y1;

$profile_y3=$profile_y2+$profile_pic_height;
$profile_y4=$profile_y3;

/* Control points for the distortion */     
  $controlPoints=array( 
     0,0, ($x1-$profile_x1),($y1-$profile_y1) , # top left  
     $im->getImageWidth(),0, $im->getImageWidth()-($x2-$profile_x2),($y2-$profile_y2), # top right
     0,$im->getImageHeight(),($x4-$profile_x4),$im->getImageHeight()-($y4-$profile_y4), # bottom LEFT 
     $im->getImageHeight(),$im->getImageWidth(),$im->getImageHeight()-($y3-$profile_y3),$im->getImageWidth()-($x3-$profile_x3)# bottum RIGHT
 );
$im->distortImage(Imagick::DISTORTION_PERSPECTIVE, $controlPoints, true);
$background = new Imagick($frame_path);
$background->writeImage($target_frame_path);
?>