Scaling functions

svn: r757
This commit is contained in:
Don Allingham 2002-02-06 06:05:01 +00:00
parent ad1db164b8
commit e75b7162d2

View File

@ -91,6 +91,22 @@ class ImgManip:
im = im.convert("RGB") im = im.convert("RGB")
return im.tostring("jpeg","RGB") return im.tostring("jpeg","RGB")
def jpg_scale_data(self,x,y):
if no_pil:
cmd = "%s -geometry %dx%d '%s' 'jpg:-'" % (const.convert,x,y,self.source)
r,w = popen2.popen2(cmd)
buf = r.read()
r.close()
w.close()
return buf
else:
im = PIL.Image.open(self.source)
im.thumbnail((x,y))
if im.mode != 'RGB':
im.draft('RGB',im.size)
im = im.convert("RGB")
return im.tostring("jpeg","RGB")
def eps_data(self): def eps_data(self):
if no_pil: if no_pil:
cmd = "%s '%s' 'eps:-'" % (const.convert,self.source) cmd = "%s '%s' 'eps:-'" % (const.convert,self.source)
@ -123,7 +139,7 @@ class ImgManip:
g = StringIO.StringIO() g = StringIO.StringIO()
im = PIL.Image.open(self.source) im = PIL.Image.open(self.source)
im.thumbnail((width,height)) im.thumbnail((x,y))
if im.mode != 'RGB': if im.mode != 'RGB':
im.draft('RGB',im.size) im.draft('RGB',im.size)
im = im.convert("RGB") im = im.convert("RGB")
@ -133,6 +149,21 @@ class ImgManip:
g.close() g.close()
return buf return buf
def png_data(self):
if no_pil:
cmd = "%s -geometry '%s' 'jpg:-'" % (const.convert,self.source)
r,w = popen2.popen2(cmd)
buf = r.read()
r.close()
w.close()
return buf
else:
im = PIL.Image.open(self.source)
if im.mode != 'RGB':
im.draft('RGB',im.size)
im = im.convert("RGB")
return im.tostring("png","RGB")
def png_scale_data(self,x,y): def png_scale_data(self,x,y):
if no_pil: if no_pil:
cmd = "%s -geometry %dx%d '%s' 'jpg:-'" % (const.convert,x,y,self.source) cmd = "%s -geometry %dx%d '%s' 'jpg:-'" % (const.convert,x,y,self.source)
@ -143,9 +174,10 @@ class ImgManip:
return buf return buf
else: else:
im = PIL.Image.open(self.source) im = PIL.Image.open(self.source)
im.thumbnail((width,height)) im.thumbnail((x,y))
if im.mode != 'RGB': if im.mode != 'RGB':
im.draft('RGB',im.size) im.draft('RGB',im.size)
im = im.convert("RGB") im = im.convert("RGB")
return im.tostring("png","RGB") return im.tostring("png","RGB")