/ Published in: Python
                    
                                        I had an icon representing a little blue dot and needed to create 100 copies each with a number in them. 
Python saves the day yet again.
                Python saves the day yet again.
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
 #requires http://www.pythonware.com/products/pil/ import Image, ImageFont, ImageDraw def add_number(number): '''Add the number to the center of an icon and save it to a new image Useful for generating multiple icons''' image = Image.open(r'C:\python\temp\bd.png') font=ImageFont.truetype("arial.ttf", 55) #, encoding='utf-8') draw=ImageDraw.Draw(image) x=(image.size[0]-draw.textsize(number,font)[0])/2 y=(image.size[1]-draw.textsize(number,font)[1])/2 draw.text((x,y),number,font=font,fill='#FFFFFF') #image.show() image.save(r'C:\python\temp\bd%s.png'%number) for i in range(1,101): add_number(str(i))
URL: http://snipplr.com/?success
Comments
                    Subscribe to comments
                
                