Created
August 23, 2011 03:17
-
-
Save zonble/1164254 to your computer and use it in GitHub Desktop.
大字產生器
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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