Tcpdf Rendering images of different dimensions in a pdf (using PHP) ← (PHP)

one text

I am fetching dynamic logo images from a URL from our client and have to place the image at a specific space in pdf (Using TCPDF). I need to preserve the aspect ratio of the image and also the image should not overlap or go beyond the space allotted for the image in the pdf. As of now I have given width as 0 and height as 10 in the Image function so that it will auto calculate the width.

$this->Image($imagefromUrl,12, 270, 0, 10, $type='', $link='', $align='', $resize=false, $dpi=300, $palign='', $ismask=false, $imgmask=false, $border=0, $fitbox=false, $hidden=false, $fitonpage=false, $alt=false, $altimgs=array());

But the above approach is not working for all the images since for some images width is larger and for some images height is larger. For example image with "2671x350" dimensions , there is no control over the image width its just overlaps the other context in the pdf. Can some help me to understand and place images in the pdf preserving the aspect ratio of the image? thanks

Source