bitmap2ttf icon indicating copy to clipboard operation
bitmap2ttf copied to clipboard

PIL ValueError: tile cannot extend outside image

Open mobius3 opened this issue 10 years ago • 5 comments

Hello. Your project is awesome and I was amazed that it actually works.

I am trying to convert artwiz fonts (which are in pcf format) to ttf, and for some of them it shows the error in the title. Trace is this:

 Traceback (most recent call last):
  File "./pcftottf.py", line 88, in <module>
    p = PcfFontFileUnicode(file(filename))
  File "./pcftottf.py", line 38, in __init__
    bitmaps = self._load_bitmaps(metrics)
  File "/usr/lib64/python2.7/site-packages/PIL/PcfFontFile.py", line 223, in _load_bitmaps
    Image.frombytes("1", (x, y), data[b:e], "raw", mode, pad(x))
  File "/usr/lib64/python2.7/site-packages/PIL/Image.py", line 1825, in frombytes
    im.frombytes(data, decoder_name, args)
  File "/usr/lib64/python2.7/site-packages/PIL/Image.py", line 601, in frombytes
    d.setimage(self.im)
ValueError: tile cannot extend outside image

Do you know whats possibly going on? For some other files, it works.

mobius3 avatar Mar 05 '14 05:03 mobius3

I'm not sure. Which specific font are you having a problem with and where can I get it?

ali1234 avatar Mar 05 '14 20:03 ali1234

Its from this package: http://sourceforge.net/projects/artwizaleczapka/files/iso-8859-1/1.3/artwiz-aleczapka-en-1.3.tar.bz2/download

You can test using nu.pcf

mobius3 avatar Mar 05 '14 20:03 mobius3

This font defines a zero pixels wide glyph for the space character which PIL cannot correctly handle. I think this is a bug in PIL's PCF loader, but it wouldn't convert properly anyway. At best you'd get a ttf where space is 0 pt wide. Probably the spacing would be all wrong for all the other characters as well.

ali1234 avatar Mar 05 '14 22:03 ali1234

I see, thanks for digging it up.

Well is there a way to fix the font? Corrections can be submitted to the authors.

mobius3 avatar Mar 06 '14 01:03 mobius3

Ok, so I converted the font to bcf, edited the bitmaps and converted again to pcf and then ran bitmap2ttf, but the result for the nu font is very bad. Any ideas?

This is the corrected font: https://www.dropbox.com/s/lhk55hed193plra/nu-corrected.pcf

mobius3 avatar Mar 09 '14 00:03 mobius3