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.
A point is equal to a specific number of pixels depending on the screen resolution. Put simply, at 1x resolution, 1pt = 1px. At 2x resolution, 1pt = 4px because the resolution doubles both the X and Y values, so 2 x 2px. At 3x resolution, 1pt = 9px, which is 3 x 3px and so on.
How many PX is a PT? One point is the equivalent of 1.333(3) pixels. On the other hand, one pixel is the equivalent of 0.75 points.
Font size specifications may come in points or pixels where: 1 pixel (px) is usually assumed to be 1/96th of an inch. 1 point (pt) is assumed to be 1/72nd of an inch. Therefore 16px = 12pt.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With