2017-10-28 49 views
0

我使用TCPDF,我需要根据图像左下角的坐标放置图像。根据左下角坐标tcpdf放置图像

TCPDFs图像()方法使用左上角为锚点,我没有找到一个可能改变这一点:

Image($file, $x = '', $y = '', $w = 0, $h = 0, $type = '', $link = '', $align = '', $resize = false, $dpi = 300, $palign = '', $ismask = false, $imgmask = false, $border = 0, $fitbox = false, $hidden = false, $fitonpage = false, $alt = false, $altimgs = array()) 

我能做的就是确定图像的Y大小和从我给定的左下角的y坐标中减去图像的y尺寸。但在放置图像之前,我也不知道如何获取图像的大小。

回答

0

如果给出了左下角的y坐标,首先运行带有一些$ y值的图像方法,并将$ hidden属性设置为true。然后使用方法getImageRBY()检索隐藏图像的底部y坐标。从getImageRBY()获得的坐标中扣除$ y值,以获得图像的高度。

然后扣除从底部y坐标图像的高度和你有$ y值之图像()方法需要放置图像:

// my bottom left coordinate of the image 
$my_bottom_y_coordinate = 'somevalue'; 

// This is just to calculate the height 
$dummy_y = 'somedummyvalue'; 

// Run the Image function with $hidden set to true, so the image won't be shown. 
$tcpdf->Image($file, $x, $dummy_y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, $ismask, $imgmask, $border, $fitbox, TRUE, $fitonpage, $alt, $altimgs); 

// get the bottom y-coordinate of the dummy image and deduct it from the 
// $dummy_y variable (which was the upper y coordinate of the dummy image) to retrieve the height 
$height = $tcpdf->getImageRBY() - $dummy_y; 

// deduct the height from the given bottom y coordinate you really want to use. This yields the upper y coordinate you need for the image function. 
$y = $my_bottom_y_coordinate - $height; 

// run the Image() method again this time with hidden false so the image is actually placed on the pdf page 
$tcpdf->Image($file, $x, $y, $w, $h, $type, $link, $align, $resize, $dpi, $palign, $ismask, $imgmask, $border, $fitbox, FALSE, $fitonpage, $alt, $altimgs);