PIL question. having exactly same font on multiple platforms
gelonida at gmail.com
Thu Aug 4 19:37:04 EDT 2011
Thanks again to everybody,
Your answers helped me to understand better.
My pragmatic solution is now to package my program
with an open source .ttf font,
which will be used on both platforms.
On 08/04/2011 10:24 PM, Irmen de Jong wrote:
> On 4-8-2011 21:30, Irmen de Jong wrote:
>> As far as I know, I did not see any difference in output on windows, linux and mac os x
>> as long as the code used the same ttf file and PIL versions. (but I'll double check now
>> and see if I remember this correctly).
> To follow up on myself, I've just tested it with the same ttf file on windows, os x and
> linux. (made an image in font size 40 with 'The quick brown fox....' as text line) The
> resulting image files were byte-identical between os x and linux but the windows ones
> were slightly different (just by a few bytes). The text in the image itself looked
> identical though to the ones from the other systems (I couldn't see any difference by
> looking at it) so I presume the difference is in the image compression or file header
> PIL's font rendering seems to produce identical results across platforms and if you see
> a difference it must be caused by a difference in typeface file (or perhaps a different
> PIL/freetype version on the platform).
What I finally did was following:
I copied a ttf font whoose copyright seems to be permissive ('Vera.ttf')
from my linux machine to my windows host.
I wrote following script:
import ImageFont, ImageDraw
im = Image.new( "RGB", (250,60) , "#000000" )
draw = ImageDraw.Draw(im)
font = ImageFont.truetype("Vera.ttf", 40)
draw.text((5, 5), "Hello world", font=font)
im = Image.open('img.png')
iml = Image.open('img_other.png')
diff = ImageChops.difference(im, iml)
and ran it on one machine
then I copied the generated file img.png to my other platform and
renamed it to img_other.png
then I ran my script there
and displayed diff.png
What I see (but I do not have the same version of PIL on both machines)
is, that the images are different, though the difference as rather local
and not too huge.
So copying an open source ttf font to my windows machine
creates fonts, which are from an optical aspect similair enough.
I will still check whether the imgaes are identical if using the same
font file and the same PIL version.
THis should clarify whether the OS is involved in rendering the images
If really wanted to run automated tests verifying the image result I
could still do it by saving the md5sums for both platforms and veryfing
whether the result is identical to one of them.
More information about the Python-list