Better image handing/conversion

svn: r759
This commit is contained in:
Don Allingham 2002-02-07 00:51:07 +00:00
parent 111f053c08
commit 50661365f2
3 changed files with 55 additions and 16 deletions

View File

@ -55,20 +55,6 @@ class ImgManip:
im = im.convert("RGB") im = im.convert("RGB")
im.save(dest,"JPEG") im.save(dest,"JPEG")
def png_thumbnail(self,dest,width,height):
if no_pil:
w = int(width)
h = int(height)
cmd = "%s -geometry %dx%d '%s' 'png:%s'" % (const.convert,w,h,self.source,dest)
os.system(cmd)
else:
im = PIL.Image.open(self.source)
im.thumbnail((width,height))
if im.mode != 'RGB':
im.draft('RGB',im.size)
im = im.convert("RGB")
im.save(dest,"PNG")
def size(self): def size(self):
if no_pil: if no_pil:
img = GdkImlib.Image(self.source) img = GdkImlib.Image(self.source)
@ -149,6 +135,33 @@ class ImgManip:
g.close() g.close()
return buf return buf
def eps_thumbnail(self,dest,width,height):
if no_pil:
w = int(width)
h = int(height)
cmd = "%s -geometry %dx%d '%s' 'eps:%s'" % (const.convert,w,h,self.source,dest)
os.system(cmd)
else:
im = PIL.Image.open(self.source)
im.thumbnail((width,height))
if im.mode != 'RGB':
im.draft('RGB',im.size)
im = im.convert("RGB")
im.save(dest,"eps")
def eps_convert(self,dest):
if no_pil:
cmd = "%s -geometry '%s' 'eps:%s'" % (const.convert,self.source,dest)
os.system(cmd)
else:
im = PIL.Image.open(self.source)
im.thumbnail((width,height))
if im.mode != 'RGB':
im.draft('RGB',im.size)
im = im.convert("RGB")
im.save(dest,"eps")
def png_data(self): def png_data(self):
if no_pil: if no_pil:
cmd = "%s -geometry '%s' 'jpg:-'" % (const.convert,self.source) cmd = "%s -geometry '%s' 'jpg:-'" % (const.convert,self.source)
@ -180,4 +193,29 @@ class ImgManip:
im = im.convert("RGB") im = im.convert("RGB")
return im.tostring("png","RGB") return im.tostring("png","RGB")
def png_thumbnail(self,dest,width,height):
if no_pil:
w = int(width)
h = int(height)
cmd = "%s -geometry %dx%d '%s' 'png:%s'" % (const.convert,w,h,self.source,dest)
os.system(cmd)
else:
im = PIL.Image.open(self.source)
im.thumbnail((width,height))
if im.mode != 'RGB':
im.draft('RGB',im.size)
im = im.convert("RGB")
im.save(dest,"PNG")
def png_convert(self,dest)
if no_pil:
cmd = "%s '%s' 'png:%s'" % (const.convert,self.source,dest)
os.system(cmd)
else:
im = PIL.Image.open(self.source)
if im.mode != 'RGB':
im.draft('RGB',im.size)
im = im.convert("RGB")
im.save(dest,"PNG")

View File

@ -251,8 +251,8 @@ class OpenOfficeDoc(TextDoc):
self.f.write('draw:name="') self.f.write('draw:name="')
self.f.write(tag) self.f.write(tag)
self.f.write('" text:anchor-type="paragraph" ') self.f.write('" text:anchor-type="paragraph" ')
self.f.write('svg:width="%.3fcm" ' % x_cm*scale) self.f.write('svg:width="%.3fcm" ' % (x_cm*scale))
self.f.write('svg:height="%.3fcm" ' % y_cm*scale) self.f.write('svg:height="%.3fcm" ' % (y_cm*scale))
self.f.write('draw:z-index="0" ') self.f.write('draw:z-index="0" ')
self.f.write('xlink:href="#Pictures/') self.f.write('xlink:href="#Pictures/')
self.f.write(base) self.f.write(base)

View File

@ -25,6 +25,7 @@
#------------------------------------------------------------------------ #------------------------------------------------------------------------
from TextDoc import * from TextDoc import *
import Plugins import Plugins
import ImgManip
import intl import intl
_ = intl.gettext _ = intl.gettext