Python Example Program - Pillow Thumbnail

Опубликовано: 13 Январь 2019
на канале: Sequenze2
208
0

In this example program I show you how to generate thumbnail pictures with the Pillow package for Python. These thumbnails you can use for Youtube videos.
The advantage with this method it that it is fast and consistent producing images with the same layout every time..

Enjoy the video and do not forget to subscribe to my channel.

kind regards,

@SEQUENZE2



If you like this video, do not forget to like and subscribe to my channel!!.
so you will not miss any of my next video's
https://bit.ly/2rrmKx5

Follow me on Instagram:

www.instagram.com/Sequenze2
DO NOT CLICK!! https://bit.ly/2rrmKx5

I used Google Fonts in this video, they are free to be used.


Full python script

in this example program I show you how to generate thumbnail pictures
to use for Youtube videos
the advantage with this method it that it is fast and consistent producing images
with the same layout every time..
kind regards, @SEQUENZE2


Start by importing the required classes
from PIL import Image, ImageDraw, ImageFont

create Image object with the input image
image = Image.open('D:\\TestDoc\\Industrie.jpg') # or any other folder with your image
get the dimensions of the image ( used in the script to place the text)
width, height = image.size

initialise the drawing context with
the image object as background
draw = ImageDraw.Draw(image, 'RGBA')

create font objects with the font file and specify desired size
fontfile = 'D:\\TestDoc\\Comfortaa-Bold.ttf'
font = ImageFont.truetype(fontfile, size=80)
font1 = ImageFont.truetype(fontfile, size=70)
font2 = ImageFont.truetype(fontfile, size=50)
and the color of the font
colorFont = 'rgb(255, 255, 255)'

to get the average color of the image resize it to 1x1 pixel
this is done to get better contrast for the text
img2 = image.resize((1, 1))
get color of the pixel
pxcolor = img2.getpixel((0, 0))
create 3 variables for the RGB values
c1 = pxcolor[0]
c2 = pxcolor[1]
c3 = pxcolor[2]

define function drawmsg
def drawmsg(x,y,message,font,color,trans):
get the dimensions of the text
w, h = draw.textsize(message, font=font)
draw a rectangle behind the text to make it more stand out / higher contrast
draw.rectangle([(x-w/2-10, y+h/2+10), (x+w/2+10, y-h/2-5)], (c1, c2, c3, trans)) #111 159 237
put the text on the image
draw.text((x-w/2, y-h/2), message, fill=color, font=font)

call the drawmsg function 3 times to put in the descriptions

dt1 = drawmsg(width/2, 80,'PYTHON EXAMPLE PROGRAM',font,colorFont,0)
dt2 = drawmsg(width/2, height/4,'Thumbnail Generation with PILLOW',font1,colorFont,150)
dt3 = drawmsg(width/2, height - 100,'@SEQUENZE2',font2,colorFont,150)

at the end we need to save the image to a file
save the edited image

image.save('D:\\TestDoc\\Thumbnail_1.png')

save and run your script and show the result....
feel free to tweak the colors and fonts as you like,
thanks for watching and if you want to make sure not to miss any of my tutorials
subscribe to my channel and don't forget to click the BELL!!


На этой странице сайта вы можете посмотреть видео онлайн Python Example Program - Pillow Thumbnail длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь Sequenze2 13 Январь 2019, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 208 раз и оно понравилось 0 зрителям. Приятного просмотра!