title: Apply image perspective feature through gimp batch mode
body: <p>I have 2 images,</p>
  
  <p>first is of news paper and second is of a person's face.</p>
  
  <p>I am writing a php program, purpose of that is to fix a person's face in news paper. below is the news paper image.</p>
  
  <p><img src="https://i.stack.imgur.com/SXUKk.png" alt="News paper image"></p>
  
  <p>I am getting perosn's profile pic through an api, sometime it is a little bit bigger than white place holder and sometime smaller (Have no control over that)</p>
  
  <p>I tested Image perspective feature in Gimp 2.8 and fixed the profile pic in white place holder perfectly</p>
  
  <p><img src="https://i.stack.imgur.com/zCEVt.png" alt="enter image description here"></p>
  
  <p>I have tried <code>Imagick</code> class' <a href="http://www.php.net/manual/en/imagick.distortimage.php" rel="nofollow noreferrer">distortImage()</a> method with <a href="http://www.php.net/manual/en/imagick.compositeimage.php" rel="nofollow noreferrer">compositeImage()</a> method to rotate and profile pic and fix it in news paper, but problem is <code>distortImage()</code> method 
  increases size of a profile pic randomly.</p>
  
  <p>I have also tried <a href="https://github.com/claviska/SimpleImage/blob/master/readme.md" rel="nofollow noreferrer">SimpleImage</a> class, used <code>rotate()</code> and <code>overlay()</code> methods to achieve the goal, but faced same problem that profile pic's size gets increased and eventually have to deal with some hard coding.</p>
  
  <p>In above both approach I need to hard code start positions (however it should always be top left corner of place holder).</p>
  
  <p>There are more than 100 images of news paper with image place holder, the position of place holder gets changes from one image to another (they are basically frames of one small video)</p>
  
  <p>Now the question is, is it possible to do this through gimp batch mode ?? then want to write script to achieve this task.</p>
  
  <p>I have tried to find documentation online to know how to write script for image perspective function in gimp batch, but didn't reach to perfect place :(</p>
  
  <p>Kindly guide accordingly.</p>
  
  <p>If any other image processing tool is available on Ubuntu, which facilitates to write script and let required operation done, then I can use that image processing tool/software as well.</p>
  
  <p>Code </p>
  
  <pre><code>&lt;?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-&gt;setImageVirtualPixelMethod(Imagick::VIRTUALPIXELMETHOD_TRANSPARENT);
  $im-&gt;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-&gt;getImageWidth(),0, $im-&gt;getImageWidth()-($x2-$profile_x2),($y2-$profile_y2), # top right
       0,$im-&gt;getImageHeight(),($x4-$profile_x4),$im-&gt;getImageHeight()-($y4-$profile_y4), # bottom LEFT 
       $im-&gt;getImageHeight(),$im-&gt;getImageWidth(),$im-&gt;getImageHeight()-($y3-$profile_y3),$im-&gt;getImageWidth()-($x3-$profile_x3)# bottum RIGHT
   );
  $im-&gt;distortImage(Imagick::DISTORTION_PERSPECTIVE, $controlPoints, true);
  $background = new Imagick($frame_path);
  $background-&gt;writeImage($target_frame_path);
  ?&gt;
  </code></pre>
  
  <p>Thanks in advance.</p>