Pythonity / icon-font-to-png

Python script (and library) for exporting icons from icon fonts (e.g. Font Awesome, Octicons) as PNG images
https://pythonity.github.io/icon-font-to-png/
MIT License
209 stars 34 forks source link

NoneType error on bbox #11

Open bersace opened 6 years ago

bersace commented 6 years ago

Hi,

Trying to workaround FontAwesome awkwardness, i hit a bug with bounding box management. Here is the output:

$ icon-font-to-png --css my-font-awesome.css --ttf my-fontawesome-webfont.ttf ALL
Exporting icon '500px' as '500px.png'(16x16 pixels)
Traceback (most recent call last):
  File "/home/bersace/.local/share/virtualenvs/pandocker/bin/icon-font-to-png", line 16, in <module>
    command_line.run(sys.argv[1:])
  File "/home/bersace/.local/share/virtualenvs/pandocker/lib/python3.5/site-packages/icon_font_to_png/command_line.py", line 161, in run
    color=args.color, scale=args.scale)
  File "/home/bersace/.local/share/virtualenvs/pandocker/lib/python3.5/site-packages/icon_font_to_png/icon_font.py", line 155, in export_icon
    border_w = int((size - (bbox[2] - bbox[0])) / 2)
TypeError: 'NoneType' object is not subscriptable
52             if bbox:                                                         
153                 icon_image = icon_image.crop(bbox)
154                                                                        
155  ->         border_w = int((size - (bbox[2] - bbox[0])) / 2)
156             border_h = int((size - (bbox[3] - bbox[1])) / 2)
157                                
158             # Create output image
159             out_image = Image.new("RGBA", (size, size), (0, 0, 0, 0))
160             out_image.paste(icon_image, (border_w, border_h))

I don't understand why there is an if bbox as if bbox can be None, but border_* lines requires bbox to be defined. Can you give me a clue ? I can send you a patch.

pawelad commented 6 years ago

Thanks for reporting, I'll try to find some time for the Font Awesome 5 compatibility in the next few days to fix both this and #10 and do a release.

I don't understand why there is an if bbox as if bbox can be None, but border_* lines requires bbox to be defined. Can you give me a clue ? I can send you a patch.

Very good point : -) I'm afraid I don't know the answer the the top of my head, but it definitely looks sketchy.

dteirney commented 5 years ago

I ran into this issue trying to use Font Awesome 5 as well. I fixed the BBox error but then ended up with blank images, which didn't help. Root problem seems to be because the font-awesome 5 CSS file includes all of the class names but the different TTF files don't contain all of the glyphs. To generate icons based solely on the icon name, I had to alter my script to try the regular TTF file and, if that returned an error, try the solid TTF file.

aaronwhite commented 4 years ago

Hoping for a bump in case @pawelad has a secret branch ready to go, or if @dteirney wouldn't mind sharing his fix! Thanks, all!

youradds commented 2 years ago

Was this ever fixed? I'm getting an error even with a simple usecase:

 icon-font-to-png --css ./css/all.css --ttf ./webfonts/fa-regular-400.ttf ALL
Exporting icon '500px' as '500px.png'(16x16 pixels)
Traceback (most recent call last):
  File "/usr/local/bin/icon-font-to-png", line 16, in <module>
    command_line.run(sys.argv[1:])
  File "/usr/local/lib/python3.8/dist-packages/icon_font_to_png/command_line.py", line 160, in run
    icon_font.export_icon(icon=icon, filename=filename, size=args.size,
  File "/usr/local/lib/python3.8/dist-packages/icon_font_to_png/icon_font.py", line 155, in export_icon
    border_w = int((size - (bbox[2] - bbox[0])) / 2)
TypeError: 'NoneType' object is not subscriptable