Skip to content

Instantly share code, notes, and snippets.

@zonble
Created August 23, 2011 03:17
Show Gist options
  • Save zonble/1164254 to your computer and use it in GitHub Desktop.
Save zonble/1164254 to your computer and use it in GitHub Desktop.
大字產生器
#!/usr/bin/python
# -*- coding:utf-8 -*-
import objc
from Cocoa import *
def bigText(text):
attrs = {NSFontAttributeName : NSFont.boldSystemFontOfSize_(200.0)}
attributedString = NSAttributedString.alloc().initWithString_attributes_(text, attrs)
frame = attributedString.boundingRectWithSize_options_(NSMakeSize(640.0, 1600.0), 0)
image = NSImage.alloc().initWithSize_(frame.size)
image.lockFocus()
attributedString.drawInRect_(NSMakeRect(0.0, 0.0, frame.size.width, frame.size.height))
bitmap = NSBitmapImageRep.alloc().initWithFocusedViewRect_(NSMakeRect(0.0, 0.0, frame.size.width, frame.size.height))
image.unlockFocus()
data = bitmap.representationUsingType_properties_(NSPNGFileType, None)
data.writeToFile_atomically_("/Users/zonble/Desktop/test.png", True)
bigText(u"大字產生器")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment