Reputation: 190
I use TCPDF and I need to place an image according to the coordinates of the bottom left corner of the image.
TCPDFs image() method uses the upper left corner as anchor point and I don't find a possibility to change this:
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. But I also don't know how to get the image y size before placing the image.
Upvotes: 0
Views: 2398
Reputation: 190
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. Then use method getImageRBY() to retrieve the bottom y coordinate of the hidden image. Deduct the $y value from the coordinate you got from getImageRBY() and so you get the height of the image.
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:
// 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);
Upvotes: 1