I am using php and fpdf to generate a pdf. How can I scale a 400 pixel high image to fit in a 300 point high space? The dimensions are just examples, the image and available space are dynamic.
Asked
Active
Viewed 2.3k times
2 Answers
19
If you want to fit 400 pixels in 300 points, then your resizing factor would simply be 300 / 400
= 0.75. You need to put each pixel in 0.75 of a point.
But there is another story you should know: Each point is 1/72 of an inch. and how many pixels make 1 inch is a matter of choice.
All images have a property called DPI: dots per inch. It specifies how many pixels are there for each inch of the picture. So if you want to convert a 400px * 400px picture to a (say) 96 dpi image, your resizing factor will be 400 / ((72 / 96) * 400)
. 72 here is for converting inches to points.

Abel Callejo
- 13,779
- 10
- 69
- 84

Hossein
- 4,097
- 2
- 24
- 46
-
Agreed, I explained it badly. I think your first sentence answers my question. In my original question I did not know wheteher the user was using 72dpi or 96dpi(or anything else). – maddogandnoriko Jan 04 '12 at 18:11
-
I think it is how many pixels make up an inch is a matter of choice. – maddogandnoriko Jan 04 '12 at 18:14
-
You're right, I edited. But imagine a world where a single pixel is bigger than an inch, then we can talk about how many inches make one pixel. Why not? :) – Hossein Jan 04 '12 at 18:19
0
You can resize the picutre first with imagecopyresampled.

Tobias
- 9,170
- 3
- 24
- 30
-
I can resize the image but I do not know how to convert pixels to points, not knowing what the users system is set to. – maddogandnoriko Jan 04 '12 at 17:43
-
-
If the image is smaller than 300 points I do not want resize it. If it is larger I need to resize it. And all I have is pixels to test that. I also may need to resize X or Y depending on if the image is taller or wider. I see 96 dpi in the image function, should I covert using 96dpi? Or is that an assumption I should not make? – maddogandnoriko Jan 04 '12 at 17:58