Jump to content

Recommended Posts

Posted

Já tinha feito este script há algum tempo e hoje lembrei-me de postar aqui para os interessados.

O threshold varia a intensidade dos pontos brancos. Têm de ter instalado o módulo PIL (Python Imaging Library).

import Image, ImageDraw, ImageFont, random

#settings
number = str(2)
random.seed()
number2 = str(random.randint(0,100))
limit = 50
threshold = 50

#constants
size = 360, 220
black = 0, 0, 0
white = 255, 255, 255
tmp = 0, 0

#random position
x = random.randint(0, size[0]-110)
y = random.randint(0, size[1]-100)

#create objects
im = Image.new('RGB', size, black)
font = ImageFont.truetype("folks-bold.ttf", 13)
font2 = ImageFont.truetype("verdanab.ttf", random.randint(95,100))
font3 = ImageFont.truetype("ariblk.ttf", random.randint(95,100))
font4 = ImageFont.truetype("verabd.ttf", random.randint(95,100))
draw = ImageDraw.Draw(im)

#random black dots in the background
for i in xrange(size[0]):
   for e in xrange(size[1]):
       if random.randint(0,threshold) == 0:
           draw.point((i,e), white)

#write the text
fontmask = font.getmask(number, mode="")
fontmask.rotate(10)

draw.text((size[0]-15, size[1]-20), number, font=font) 

for i in number2:
   rnd = random.randint(2,4)
   if rnd == 2:
       draw.text((x+tmp[0], y), i, font=font2)
       tmp = font2.getsize(i)
   elif rnd == 3:
       draw.text((x+tmp[0], y), i, font=font3)
       tmp = font3.getsize(i)
   else:
       draw.text((x+tmp[0], y), i, font=font4)
       tmp = font4.getsize(i)

im.show()

<3 life

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.