pytroll / pycoast

Python package for adding coastlines and borders on raster images
http://pycoast.readthedocs.org/en/latest/
GNU General Public License v3.0
40 stars 20 forks source link

ImageFont.truetype problem #50

Open paapu88 opened 3 years ago

paapu88 commented 3 years ago

Dear Developers, I have Ubuntu 20.04 python 3.8.5 pycoast==1.4.0

I followed: https://github.com/pytroll/pycoast/blob/master/docs/source/graticule.rst

This did work fine:

 img = Image.open(os.path.join(outDir, outFileName))
 cw = ContourWriterAGG('/home/hu-mka/git/cyclonesatpy/cyclonesatpy/dev/shapefiles/')
 font=aggdraw.Font('black', '/usr/share/fonts/truetype/ubuntu/Ubuntu-B.ttf',opacity=127, size=16)
 cw.add_coastlines(img, areadef, resolution='l', level=4, outline=(255, 0, 0))
 cw.add_grid(img, areadef, (2.0, 2.0), (1.0, 1.0), font, fill='blue',
 outline = 'blue', minor_outline = 'blue')

But if i replace font by: font = ImageFont.truetype('/usr/share/fonts/truetype/freefont/FreeSans.ttf', 16) I get:

TypeError: text() argument 2 must be Font, not FreeTypeFont Terveisin, Markus

djhoese commented 3 years ago

If the aggdraw.Font works for you, is there a reason you need to use the ImageFont.truetype option?

The basic excuse on our end is that there are some incompatibilities between the old "PIL" based writer and the AGG-based writer. The AGG writer depends on "aggdraw" which is the real problem here as that library doesn't support PIL's ImageFont objects and pycoast does not currently have a way to wrap/workaround that (ex. convert ImageFont objects from the user to Font objects for aggdraw).

paapu88 commented 3 years ago

Hei, I'm fine now, but please remove ImageFont.truetype if you have it in the documentation (not sure that's the case) so other people will not waste their time (I wasted 15min of my precious time...). But really a great package!! Thanks! Markus

djhoese commented 3 years ago

ImageFont.truetype if you have it in the documentation (not sure that's the case)

ImageFont objects can still be used with the PIL writer which is still available and used to be the default writer. If you aren't sure it is in the documentation, then where did you see that you should use it? Is there something that needs updating? Any help would be greatly appreciated.

paapu88 commented 3 years ago

Aa, it was here (first thing google gave me) https://github.com/pytroll/pycoast/blob/master/docs/source/graticule.rst