2017-06-12 104 views
0

所以我使用TCPDF为了在PDF输出上做一些图像处理。TCPDF使用相同转换内的矩形多边形旋转和剪辑

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

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

有没有办法旋转图像,然后在旋转初始化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正是我想要的那样。

回答

0

因此经过多次实验后,我发现在做实际旋转之前发布'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();