Reputation: 1850
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?
Upvotes: 2
Views: 25548
Reputation: 138
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));
Upvotes: 4