简体   繁体   中英

How to scale an Image in FPDF (PHP)

I am trying to add an image using FPDF with:

$pdf->Cell(90, 120, "", 0, 1, 'C',$pdf->Image($img1,10,70,0,90));

So this will make width proportional with the height that is set, but the problem is when the width is bigger than height..

I would like somehow to fit the image , to scale it normally without setting up fixed values for width and height, so if the width is bigger -> scale the height and if height is bigger -> scale the width.

Any help?

If you don't know the dimensions, you'll have to figure out which of the height or width is the limiting factor, and then use 0 for the other (Image() will calculate it if only one dimension is non zero):

list($x1, $y1) = getimagesize($img1);
$x2 = 10;
$y2 = 70;
if(($x1 / $x2) < ($y1 / $y2)) {
    $y2 = 0;
} else {
    $x2 = 0;
}
$pdf->Cell(90, 120, "", 0, 1, 'C',$pdf->Image($img1,$x2,$y2,0,90));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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