Python Forum
Question about ImagePath.Path() in Pillow library
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Question about ImagePath.Path() in Pillow library
#1
Hi!

I've been learning how to use the various packages and methods in the Pillow library (v9.4.0 under Python 3.7.9), but I have a question about the ImagePath.Path class in the ImagePath module. If I run the example below, I get the same result whether I pass a Path object to Image.line() or I pass an ordinary list of tuples. So is there any reason to use ImagePath if you don't need to call any of its methods (compact(),getbox(), map(), toList(), transform())? In other words, simply creating an Path object doesn't really do anything? It's only the associated methods that do anything useful?

from PIL import Image, ImageDraw, ImagePath

img = Image.new("RGB",(800,400),(255,255,0))
cnv = ImageDraw.Draw(img)
#path = [(0,0),(250,300),(500,250),(0,0)]
path = ImagePath.Path([(0,0),(250,300),(500,250),(0,0)])
cnv.line(path,(0,0,0),3)
img.save("test.jpg")
Reply
#2
(Jan-24-2023, 01:35 PM)dfkettle Wrote: So is there any reason to use ImagePath if you don't need to call any of its methods (compact(),getbox(), map(), toList(), transform())? In other words, simply creating an Path object doesn't really do anything?
Yes,you call methods if need eg more info like bounding box of the path.
Then call method getbox().
from PIL import Image, ImageDraw, ImagePath

img = Image.new("RGB",(800,400),(255,255,0))
cnv = ImageDraw.Draw(img)
path = ImagePath.Path([(0,0),(250,300),(500,250),(0,0)])
# Use getbbox() method to get bounding box of the path
>>> path.getbbox()
(0.0, 0.0, 500.0, 300.0)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  WebDriverException: Message: 'PATH TO CHROME DRIVER' executable needs to be in PATH Led_Zeppelin 1 2,149 Sep-09-2021, 01:25 PM
Last Post: Yoriz
  .pth file does not show up in sys.path when configuring path. arjunsingh2908 2 5,669 Jul-03-2018, 11:16 AM
Last Post: arjunsingh2908
  PIL or pillow? newbie question. tony1812 2 11,841 Sep-13-2017, 06:18 AM
Last Post: nilamo
  PyInstaller, how to create library folder instead of library.zip file ? harun2525 2 4,740 May-06-2017, 11:29 AM
Last Post: harun2525

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020