TCPDF 在同一转换中使用矩形多边形进行旋转和裁剪

TCPDF Rotate and Clip using a Rect Polygon inside the same transformation

所以我使用 TCPDF 对 PDF 输出进行一些图像处理。

我有一张图像(需要旋转)和一个基于矩形多边形的剪贴蒙版。

我面临的问题是,当我进行旋转图像的变换时,我用来进行裁剪的 Rect Polygon 也在旋转。

有没有办法旋转图像,然后在执行旋转的初始 StopTransform 后进行裁剪?

下面是一些示例代码:

PDF::setXY($x, $y);
PDF::StartTransform();
PDF::Rotate($objectImageRotation * -1);
PDF::Rect($rectx, $recty, $rectwidth, $rectheight, 'CNZ');
PDF::Image($objectImageSrc, $x, $y, $width, $height, '', '', '', true, 300, '', false, false, ($objectBorderWidth > 0 ? 1 : 0), false, false, false);
PDF::StopTransform();

现在在上面,$rectx、$recty、$rectwidth 和 $rectheight 正是我想要的位置。

因此,经过大量实验后,我发现在进行实际旋转之前发布 'Rect' 是满足我要求的关键。

鉴于以上情况,以下更改对我有用:

    ' Translate to a new XY coordinate in preparation for the placement of the image
PDF::setXY($x, $y);

    ' Start the transformation including the clipping according to the given shape and then rotating as per the rotation parameter
PDF::StartTransform();

    ' Clipping Rectangle
PDF::Rect($rectx, $recty, $rectwidth, $rectheight, 'CNZ');

    ' Rotate
PDF::Rotate($objectImageRotation * -1);

    ' Place the image at the set rotation
PDF::Image($objectImageSrc, $x, $y, $width, $height, '', '', '', true, 300, '', false, false, ($objectBorderWidth > 0 ? 1 : 0), false, false, false);

    ' Stop the transformation (reset)
PDF::StopTransform();