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.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
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.
回答2:
You can resize the picutre first with imagecopyresampled.
-> Basic Example
-> Adding image to pdf