首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP - FPDI -旋转图像

PHP - FPDI -旋转图像
EN

Stack Overflow用户
提问于 2016-04-23 18:24:27
回答 1查看 2.9K关注 0票数 0

我正在使用FPDI在图像顶部导入PDF。我已经做好了所有的工作,但是现在我想旋转图像。下面是我的代码:

代码语言:javascript
复制
  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->x;
          if ($y == -1)
              $y = $this->y;
          if ($this->angle != 0)
              $this->_out('Q');
          $this->angle = $angle;
          if ($angle != 0) {
              $angle*=M_PI / 180;
              $c = cos($angle);
              $s = sin($angle);
              $cx = $x * $this->k;
              $cy = ($this->h - $y) * $this->k;
              $this->_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->angle != 0) {
              $this->angle = 0;
              $this->_out('Q');
          }
          parent::_endpage();
      }

  }

  function RotatedImage($file,$x,$y,$w,$angle)
  {
    //Image rotated around its upper-left corner
    $this->Rotate($angle,$x,$y);
    $this->Image($file,$x,$y,$w);
    $this->Rotate(0);
  }

  $pdf = new FPDI();

  $pdf->AddPage();

  //$pdf->Image('template/test.jpg',14,26,150);
  $pdf->RotatedImage('template/test.jpg',14,26,150,4);


  //load template
  $pdf->setSourceFile('template/photo.pdf');
  $tplIdx = $pdf->importPage(1);
  $pdf->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->useTemplate($tplIdx, 0, 0, 210.058, 296.926, true);

  $pdf->Output();

这一行运行得很好:

代码语言:javascript
复制
$pdf->Image('template/test.jpg',14,26,150);

但是,如果我尝试执行以下操作:

代码语言:javascript
复制
$pdf->RotatedImage('template/test.jpg',14,26,150,4);

我得到一个错误: FPDI: RotatedImage未定义。

我正在尝试让FPDF Rotate method (http://www.fpdf.org/en/script/script2.php)与FPDI (https://www.setasign.com/products/fpdi/about/)一起工作。

以前有没有人能做到这一点?

EN

回答 1

Stack Overflow用户

发布于 2016-04-23 19:08:23

RotatedImage()函数放在类中。

它是未定义的,因为它试图在$pdf上执行函数,但它当前存在于类的外部,所以它看不到它。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36809540

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档