2017-06-12 48 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();