Convert pixels to points for pdf

扶醉桌前 提交于 2019-12-05 19:20:15

问题


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



来源:https://stackoverflow.com/questions/8730901/convert-pixels-to-points-for-pdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!