简体   繁体   English

tcpdf根据左下角的坐标放置图像

[英]tcpdf place image according to coordinates of bottom left corner

I use TCPDF and I need to place an image according to the coordinates of the bottom left corner of the image. 我使用TCPDF,我需要根据图像左下角的坐标放置图像。

TCPDFs image() method uses the upper left corner as anchor point and I don't find a possibility to change this: TCPDFs image()方法使用左上角作为锚点,但我找不到更改此可能性的方法:

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() )

What I could do is to determine the y size of the image and deduct the y size of the image from my given y coordinate of the bottom left corner. 我所能做的就是确定图像的y大小,并从我左下角的给定y坐标中减去图像的y大小。 But I also don't know how to get the image y size before placing the image. 但是我也不知道在放置图像之前如何获得图像的大小。

If you have as given the y coordinate of the bottom left corner, first run the image method with some $y value and property $hidden set to true. 如果给定了左下角的y坐标,请首先使用$ y值并将属性$ hidden设置为true来运行image方法。 Then use method getImageRBY() to retrieve the bottom y coordinate of the hidden image. 然后使用方法getImageRBY()检索隐藏图像的底部y坐标。 Deduct the $y value from the coordinate you got from getImageRBY() and so you get the height of the image. 从您从getImageRBY()获得的坐标中减去$ y值,就可以得到图像的高度。

Then deduct the height of the image from your bottom y coordinate and you have the $y value the Image() method needs to place the image: 然后从您的底部y坐标中减去图像的高度,您就有了Image()方法放置图像所需的$ 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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM