Search code examples
pythondockerpython-imaging-libraryalpine-linux

Pillow ImageFont is different in docker/Alpine and Ubuntu


I created images for my display interface with python Pillow 4.0.0 library. I programmed a script which puts my text into the pillow picture and after converts it to a bitmap which is sent to the display.

I write text in the picture with ImageFont:

ImageFont.truetype('my_fonts/font.ttf', font_size)

Everything works fine in Ubuntu.

Correct image in Ubuntu

When I run the same programme in a Docker Alpine container with the same version of Pillow, the output is not as good as in Ubuntu:

Docker Alpine container

I hope that is recognizable (it is only 192x64px). It is not because of the fonts - all commands are linked to the same .ttf which is included next to python script. Also it is not because of Docker, when I try Docker Ubuntu container, the result is ok (same as non-docker above):

enter image description here

Unfortunately I have to use an Alpine Docker container. Do someone know how to fix it?


Solution

  • Finally when I have compiled an older version of freetype (2.4.1 from https://github.com/LuaDist/freetype), the output is fine (image from Ubuntu = image from Alpine)

    git clone https://github.com/LuaDist/freetype
    cd freetype
    ./autogen.sh
    ./configure
    make
    make install
    

    and after a restart the output from pillow truetype is fine!!