tcpdf根据左下角坐标放置图片

tcpdf place image according to coordinates of bottom left corner

我用的是TCPDF,需要根据图片左下角坐标放置图片

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

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

如果您已经给定了左下角的 y 坐标,首先 运行 image 方法将一些 $y 值和 属性 $hidden 设置为 true。然后使用方法 getImageRBY() 检索隐藏图像的底部 y 坐标。从您从 getImageRBY() 获得的坐标中减去 $y 值,这样您就可以得到图像的高度。

然后从底部 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);