title: PHP - FPDI - Rotate Image
body: <p>I am using FPDI to import a PDF over the top of an image.  I have everything working, but now I want to rotate the image.  Here is my code:</p>
  
  <pre><code>  require('fpdf.php');
    require('fpdi.php');
  
    class PDF_Rotate extends FPDI {
  
        var $angle = 0;
  
        function Rotate($angle, $x = -1, $y = -1) {
            if ($x == -1)
                $x = $this-&gt;x;
            if ($y == -1)
                $y = $this-&gt;y;
            if ($this-&gt;angle != 0)
                $this-&gt;_out('Q');
            $this-&gt;angle = $angle;
            if ($angle != 0) {
                $angle*=M_PI / 180;
                $c = cos($angle);
                $s = sin($angle);
                $cx = $x * $this-&gt;k;
                $cy = ($this-&gt;h - $y) * $this-&gt;k;
                $this-&gt;_out(sprintf('q %.5F %.5F %.5F %.5F %.2F %.2F cm 1 0 0 1 %.2F %.2F cm', $c, $s, -$s, $c, $cx, $cy, -$cx, -$cy));
            }
        }
  
        function _endpage() {
            if ($this-&gt;angle != 0) {
                $this-&gt;angle = 0;
                $this-&gt;_out('Q');
            }
            parent::_endpage();
        }
  
    }
  
    function RotatedImage($file,$x,$y,$w,$angle)
    {
      //Image rotated around its upper-left corner
      $this-&gt;Rotate($angle,$x,$y);
      $this-&gt;Image($file,$x,$y,$w);
      $this-&gt;Rotate(0);
    }
  
    $pdf = new FPDI();
  
    $pdf-&gt;AddPage();
  
    //$pdf-&gt;Image('template/test.jpg',14,26,150);
    $pdf-&gt;RotatedImage('template/test.jpg',14,26,150,4);
  
  
    //load template
    $pdf-&gt;setSourceFile('template/photo.pdf');
    $tplIdx = $pdf-&gt;importPage(1);
    $pdf-&gt;SetAutoPagebreak(false, 0);
  
    //use the imported page and place it at point 0,0; calculate width and height
    //automaticallay and ajust the page size to the size of the imported page
    $pdf-&gt;useTemplate($tplIdx, 0, 0, 210.058, 296.926, true);
  
    $pdf-&gt;Output();
  </code></pre>
  
  <p>This line works fine:</p>
  
  <pre><code>$pdf-&gt;Image('template/test.jpg',14,26,150);
  </code></pre>
  
  <p>However if I try the following:</p>
  
  <pre><code>$pdf-&gt;RotatedImage('template/test.jpg',14,26,150,4);
  </code></pre>
  
  <p>I get an error: FPDI: RotatedImage undefined.</p>
  
  <p>I am trying to get the FPDF Rotate method (<a href="http://www.fpdf.org/en/script/script2.php" rel="nofollow">http://www.fpdf.org/en/script/script2.php</a>) working with FPDI (<a href="https://www.setasign.com/products/fpdi/about/" rel="nofollow">https://www.setasign.com/products/fpdi/about/</a>)</p>
  
  <p>Has anyone managed this previously?</p>