image from filename

This commit is contained in:
Bartosz Kościów 2018-02-25 15:14:45 +01:00
parent 99c68a8363
commit 9a8de0667c
5 changed files with 14 additions and 5 deletions

View File

@ -1,3 +1,5 @@
0.8.3
- draw_image with filename or PIL object
0.8.2 0.8.2
- fix background colour in Page drawing - fix background colour in Page drawing
0.8.1 0.8.1

View File

@ -14,9 +14,10 @@ lcd_tft = ILI9325(240, 320, drv)
lcd_tft.init() lcd_tft.init()
image_file = Image.open("assets/japan_temple_240x320.jpg") # image_file = Image.open("assets/japan_temple_240x320.jpg")
lcd_tft.draw_image(0, 0, image_file) # lcd_tft.draw_image(0, 0, image_file)
numbers_image = Image.open("assets/dsp2017_101_64.png") # numbers_image = Image.open("assets/dsp2017_101_64.png")
lcd_tft.transparency_color = (0, 0, 0) lcd_tft.transparency_color = (0, 0, 0)
lcd_tft.draw_image(10, 10, numbers_image) # lcd_tft.draw_image(10, 10, numbers_image)
lcd_tft.draw_image(10, 10, "assets/dsp2017_101_64.png")

View File

@ -1,6 +1,7 @@
"""Area drawing algorithm""" """Area drawing algorithm"""
import itertools import itertools
from gfxlcd.drawing.pixel import Pixel from gfxlcd.drawing.pixel import Pixel
from PIL import Image
class Area(Pixel): class Area(Pixel):
@ -103,6 +104,8 @@ class Area(Pixel):
def draw_image(self, pos_x, pos_y, image): def draw_image(self, pos_x, pos_y, image):
"""draw a PIL image""" """draw a PIL image"""
if isinstance(image, str):
image = Image.open(image)
image_file = image.convert('RGB') image_file = image.convert('RGB')
width, height = image_file.size width, height = image_file.size
self._set_area( self._set_area(

View File

@ -1,6 +1,7 @@
"""Page drawing algorithm""" """Page drawing algorithm"""
import abc import abc
from gfxlcd.drawing.pixel import Pixel from gfxlcd.drawing.pixel import Pixel
from PIL import Image
class Page(Pixel, metaclass=abc.ABCMeta): class Page(Pixel, metaclass=abc.ABCMeta):
@ -126,6 +127,8 @@ class Page(Pixel, metaclass=abc.ABCMeta):
def draw_image(self, pos_x, pos_y, image): def draw_image(self, pos_x, pos_y, image):
"""draw a PIL image""" """draw a PIL image"""
if isinstance(image, str):
image = Image.open(image)
image_file = image.convert('L') image_file = image.convert('L')
width, height = image_file.size width, height = image_file.size
offset_x = 0 offset_x = 0

View File

@ -13,7 +13,7 @@ def read(*paths):
setup( setup(
name='gfxlcd', name='gfxlcd',
version='0.8.2', version='0.8.3',
description='gfxlcd is a handler for graphical lcds: ILI9328, SSD1306, NJU6450, touch panel: AD7843 @ Raspberry Pi.', description='gfxlcd is a handler for graphical lcds: ILI9328, SSD1306, NJU6450, touch panel: AD7843 @ Raspberry Pi.',
keywords=[ keywords=[
'gfxlcd', 'raspberry pi' ,'ili9328' ,'ssd1306', 'nju6450', 'lcd', 'graphical lcd', 'touch panel', 'ad7843', 'gfxlcd', 'raspberry pi' ,'ili9328' ,'ssd1306', 'nju6450', 'lcd', 'graphical lcd', 'touch panel', 'ad7843',