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.
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.