How to scale an Image in FPDF (PHP)
19,201
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));
![Nemanja G](https://lh5.googleusercontent.com/-Zx9-EWafdSU/AAAAAAAAAAI/AAAAAAAAAEA/CICuIkG5vAI/photo.jpg?sz=256)
Author by
Nemanja G
Updated on June 14, 2022Comments
-
Nemanja G about 2 years
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?
-
Jan Slabon over 7 yearsBut Cell() doesn't have to do anything with an Image(). So the whole Cell() call is obsolete and faulty - remove it and left a simple Image() call.