레이블이 파이썬인 게시물을 표시합니다. 모든 게시물 표시
레이블이 파이썬인 게시물을 표시합니다. 모든 게시물 표시

2009년 11월 14일 토요일

파이썬 URL 이미지 wxPython에 출력하기(print image from image by wxPython)


import wx
import urllib
class TestFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title="LI")
p = wx.Panel(self)
data = urllib.urlopen("http://www.bigtravelweb.com/images/south_america_map_l.jpg")
img = wx.ImageFromStream(data, wx.BITMAP_TYPE_JPEG).ConvertToBitmap()
wx.StaticBitmap(p, -1, img, (10, 10), (img.GetWidth(), img.GetHeight()))

app = wx.PySimpleApp()
frm = TestFrame()
frm.Show()
app.MainLoop()

2009년 11월 13일 금요일

파이썬 구글 이미지 검색(python google image search)


import urllib

class MyOpener(urllib.FancyURLopener):
version = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11'

def image_addr(word):
urllib._urlopener = MyOpener()
f = urllib.urlopen('http://images.google.com/images?hl=ko&source=hp&q='+word+'&btnG=%EC%9D%B4%EB%AF%B8%EC%A7%80+%EA%B2%80%EC%83%89&gbv=2&aq=f&oq=')
extension = '.jpg'
html = f.read()
pos2 = html.find(extension)
pos1 = html[0:pos2].rfind('http://')
return html[pos1:pos2+len(extension)]

if __name__=='__main__':
print image_addr('south')