Navigation

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Users
    • Groups
    • Solved
    • Unsolved
    • Search
    1. Home
    2. gferreira
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Gustavo Ferreira

    @gferreira

    23
    Reputation
    78
    Posts
    702
    Profile views
    3
    Followers
    0
    Following
    Joined Last Online
    Website hipertipo.com

    gferreira Follow
    admin

    Posts made by gferreira

    • RE: Saving Image with different ColorProfile

      hello @imik,

      I think conversions between color modes and color profiles are better handled with PIL/Pillow.

      here’s a small script to convert a .png image to grayscale (thanks @frederik for the example):

      from PIL import Image
      img = Image.open('image.png').convert('LA')
      img.save('greyscale.png')
      

      you can install and use Pillow from inside DrawBot using the new pip installer:

      1. go to the menu Python > Install Python packages…
      2. choose Install/Upgrade and type Pillow

      hops this helps… good luck!

      posted in General Discussion
      gferreira
    • RE: OTF file: accessing contours & segments

      hi @RicardGarcia,

      Anyway, I think I found a way to get this information by counting the amount of points in a segment so that, if there are 2 points it would be a straight line and if there are 3 a curve. Does this make sense?

      yes, except there is only 1 point in a straight segment (and 3 in a curve). the first point in a segment is always the last point from the previous one – have a look at this example.

      enjoy!

      posted in General Discussion
      gferreira
    • RE: SVG attributes (viewbox)

      hello @guidoferreyra,

      as far as I can tell, the SVG viewBox attribute is not written by DrawBot. but SVG is XML, so you can easily parse and modify it with Python after it has been created:

      # draw something, save as svg
      size(600, 200)
      fill(1, 0, 0)
      rect(50, 60, 200, 100)
      fill(0, 1, 0)
      oval(300, 50, 200, 200)
      fill(None)
      stroke(0, 0, 1)
      strokeWidth(10)
      rect(0, 0, width(), height())
      svgPath = 'svg-viewport-test.svg'
      saveImage(svgPath)
      
      # add viewBox attribute to <svg>
      from lxml.etree import parse
      xml = parse(svgPath)
      svg = xml.getroot()
      svg.attrib['viewBox'] = '0 0 180 150'
      xml.write(svgPath.replace('.svg', '_viewbox.svg'))
      

      hope this helps… cheers!

      posted in General Discussion
      gferreira
    • RE: OTF file: accessing contours & segments

      hello @RicardGarcia,

      a BezierPath is similar to a glyph. here’s how you can access the contours, segments and points:

      B = BezierPath()
      B.text('a', font='Menlo-Bold', fontSize=1000)
      
      for contour in B.contours:
          print(contour)
          for segment in contour:
              print(segment) # a segment is a list of points
          print()
      

      there’s also points, onCurvePoints and offCurvePoints.

      I hope this is what you’re looking for… cheers!

      posted in General Discussion
      gferreira
    • RE: Load font from filepath

      hi @lnp,

      the font() command can take a font name OR a path to a font file as argument:

      font('myFolder/myFont.ttf')
      

      cheers!

      posted in General Discussion
      gferreira
    • RE: Import python file.

      I could get the 'import' and 'reload' to work with a variable as the module-name, but not the 'from ... import *' part. Can I do this?

      you can access all names inside a module using dot notation: myModule.aVariable

      Also, can the module be in another folder? It's a subfolder of the root where the code is in. So not a complete other location.

      yes, the module can be anywhere, and you can tell Python where to find it by adding its parent folder to sys.path:

      import sys
      sys.path.append('/path/to/folder/')
      

      but unless you are importing code, I think using a data format like json would be more appropriate.

      good luck!

      posted in General Discussion
      gferreira
    • RE: Import python file.

      @snaders right, I forgot to mention: to update the contents of a module, you need to reload it:

      from importlib import reload
      import settings
      reload(settings)
      
      from settings import *
      print(aVariable)
      print(anotherVariable)
      

      cheers!

      posted in General Discussion
      gferreira
    • RE: Import python file.

      @MauriceMeilleur this can be a start. but creating and using a library involves a bit more:

      relative imports installed module
      imported files must be in the same folder as the main script imported files can be elsewhere
      module is imported directly with a relative import module must be installed in Python (for example appending to sys.path or using a .pth file)
      module is available only for scripts in the same folder module is available for all Python scripts

      see How To Write Modules in Python 3 for a step-by-step guide about creating your own modules.

      good luck!

      posted in General Discussion
      gferreira
    • RE: Import python file.

      hello @snaders,

      if your settings.py file lives next to your main script, you can import anything from it:

      # settings.py
      aVariable = 'hello'
      anotherVariable = 42
      
      # main.py
      from settings import *
      print(aVariable)
      print(anotherVariable)
      

      you can also store settings in plain text files or data formats, and read the data into your script. see for example the modules to read/write csv, json, plist, etc.

      hope this helps!

      posted in General Discussion
      gferreira
    • RE: PDF adding pages to existing file

      ps. see also this character set proof example using the DrawBot extension in RoboFont.

      posted in General Discussion
      gferreira