open up media asset type for all kinds of external files
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@3204 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
cb373433fa
commit
2fc1345ffa
4 changed files with 33 additions and 5 deletions
|
@ -1,5 +1,5 @@
|
|||
#
|
||||
# Copyright (c) 2007 Helmut Merz helmutm@cy55.de
|
||||
# Copyright (c) 2009 Helmut Merz helmutm@cy55.de
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
|
|
@ -80,7 +80,7 @@ class MediaAssetFile(object):
|
|||
|
||||
def getContentType(self, variant=None):
|
||||
contentType = self.getMimeType()
|
||||
if variant == None:
|
||||
if variant is None:
|
||||
return contentType
|
||||
outputFormat = None
|
||||
# Scan all statements for a defintion of an output format
|
||||
|
@ -94,7 +94,7 @@ class MediaAssetFile(object):
|
|||
# Return default type if no defintion was found
|
||||
if not outputFormat:
|
||||
baseType = getMimeBasetype(contentType)
|
||||
return DEFAULT_FORMATS.get(baseType)
|
||||
return DEFAULT_FORMATS.get(baseType) or contentType
|
||||
return outputFormat
|
||||
|
||||
def transform(self, rules=None):
|
||||
|
|
|
@ -48,12 +48,21 @@ class PILTransform(object):
|
|||
implements(IFileTransform)
|
||||
|
||||
def open(self, path):
|
||||
self.im = Image.open(path)
|
||||
try:
|
||||
self.im = Image.open(path)
|
||||
except IOError, e:
|
||||
from logging import getLogger
|
||||
getLogger('cybertools.media.piltransform.PILTransform').warn(e)
|
||||
self.im = None
|
||||
|
||||
def rotate(self, angle, resize):
|
||||
if self.im is None:
|
||||
return
|
||||
self.im = self.im.rotate(angle,Image.BICUBIC)
|
||||
|
||||
def color(self, mode):
|
||||
if self.im is None:
|
||||
return
|
||||
if not mode:
|
||||
return
|
||||
mode = mode.upper()
|
||||
|
@ -64,6 +73,8 @@ class PILTransform(object):
|
|||
self.im = self.im.convert(mode)
|
||||
|
||||
def crop(self, relWidth, relHeight, alignX=0.5, alignY=0.5):
|
||||
if self.im is None:
|
||||
return
|
||||
alignX = min(max(alignX, 0.0), 1.0)
|
||||
alignY = min(max(alignY, 0.0), 1.0)
|
||||
w, h = self.im.size
|
||||
|
@ -83,9 +94,13 @@ class PILTransform(object):
|
|||
self.im = self.im.crop(box)
|
||||
|
||||
def resize(self, width, height):
|
||||
if self.im is None:
|
||||
return
|
||||
dims = (width, height)
|
||||
self.im.thumbnail(dims, Image.ANTIALIAS)
|
||||
|
||||
def save(self, path, mimetype):
|
||||
if self.im is None:
|
||||
return
|
||||
format = mimetypeToPIL(mimetype)
|
||||
self.im.save(path)
|
||||
|
|
|
@ -44,7 +44,9 @@ class FileSystemStorage(object):
|
|||
def getDir(self, address, subDir=None):
|
||||
subDir = subDir or self.subDir
|
||||
if self.rootDir is None:
|
||||
return os.path.join(subDir, address)
|
||||
if subDir:
|
||||
return os.path.join(subDir, address)
|
||||
return address
|
||||
return os.path.join(self.rootDir, subDir, address)
|
||||
|
||||
def setData(self, address, data, params={}):
|
||||
|
@ -65,6 +67,7 @@ class FileSystemStorage(object):
|
|||
def getData(self, address, params={}):
|
||||
subDir = params.get('subdirectory')
|
||||
fn = self.getDir(address, subDir)
|
||||
#print '***', [self.rootDir, subDir, address], fn
|
||||
try:
|
||||
f = open(fn, 'rb')
|
||||
data = f.read()
|
||||
|
@ -76,6 +79,16 @@ class FileSystemStorage(object):
|
|||
#'File %r cannot be read.' % fn)
|
||||
return ''
|
||||
|
||||
def getSize(self, address, params={}):
|
||||
subDir = params.get('subdirectory')
|
||||
fn = self.getDir(address, subDir)
|
||||
try:
|
||||
return os.path.getsize(fn)
|
||||
except IOError, e:
|
||||
from logging import getLogger
|
||||
getLogger('cybertools.storage.filesystem.FileSystemStorage').warn(e)
|
||||
return 0
|
||||
|
||||
def getUniqueAddress(self, address, params={}):
|
||||
subDir = params.get('subdirectory')
|
||||
return self.getDir(address, subDir)
|
||||
|
|
Loading…
Add table
Reference in a new issue