PIL how to scale text size in relation to the size of the image

前端 未结 3 1842
Happy的楠姐
Happy的楠姐 2020-12-04 19:45

I\'m trying to dynamically scale text to be placed on images of varying but known dimensions. The text will be applied as a watermark. Is there any way to scale the text in

3条回答
  •  遥遥无期
    2020-12-04 20:18

    In general when you change the font sizing its not going to be a linear change in size of the font.

    Non-linear Scaling

    Now this often depends on the software, fonts, etc... This example was taken from Typophile and uses LaTex + Computer Modern font. As you can see its not exactly a linear scaling. So if you are having trouble with non-linear font scaling then I'm not sure how to resolve it, but one suggestion maybe is to.

    1. Render the font as closely to the size that you want, then scale that up/down via regular image scaling algorithm...
    2. Just accept that it won't exactly be linear scaling and try to create some sort of table/algorithm that will select the closest point size for the font to match up with the image size.

提交回复
热议问题