15
15
# 2002-03-15 fl PIL release 1.1.3
16
16
# 2003-05-10 fl PIL release 1.1.4
17
17
# 2005-03-28 fl PIL release 1.1.5
18
# 2006-03-03 fl PIL release 1.1.6a2
18
# 2006-06-20 fl PIL release 1.1.6b1
20
20
# Copyright (c) 1997-2006 by Secret Labs AB. All rights reserved.
21
21
# Copyright (c) 1995-2006 by Fredrik Lundh.
200
204
# @exception KeyError If the input mode was not a standard mode.
202
206
def getmodebase(mode):
203
# corresponding "base" mode (grayscale or colour)
208
return _MODEINFO[mode][0]
207
return ImageMode.getmode(mode).basemode
211
210
# Gets the storage type mode. Given a mode, this function returns a
216
215
# @exception KeyError If the input mode was not a standard mode.
218
217
def getmodetype(mode):
219
# storage type (per band)
224
return _MODEINFO[mode][1]
218
return ImageMode.getmode(mode).basetype
227
221
# Gets a list of individual band names. Given a mode, this function
234
228
# gives the number of bands in an image of the given mode.
235
229
# @exception KeyError If the input mode was not a standard mode.
231
def getmodebandnames(mode):
232
return ImageMode.getmode(mode).bands
235
# Gets the number of individual bands for this mode.
237
# @param mode Input mode.
238
# @return The number of bands in this mode.
239
# @exception KeyError If the input mode was not a standard mode.
237
241
def getmodebands(mode):
238
# return list of subcomponents
243
return len(_MODEINFO[mode][2])
242
return len(ImageMode.getmode(mode).bands)
245
244
# --------------------------------------------------------------------
1142
1139
def putdata(self, data, scale=1.0, offset=0.0):
1143
1140
"Put data from a sequence object into an image."
1145
self.load() # hmm...
1146
1146
self.im.putdata(data, scale, offset)
1240
1243
# (cubic spline interpolation in a 4x4 environment).
1241
1244
# If omitted, or if the image has mode "1" or "P", it is
1242
1245
# set <b>NEAREST</b>.
1246
# @param expand Optional expansion flag. If true, expands the output
1247
# image to make it large enough to hold the entire rotated image.
1248
# If false or omitted, make the output image the same size as the
1243
1250
# @return An Image object.
1245
def rotate(self, angle, resample=NEAREST):
1252
def rotate(self, angle, resample=NEAREST, expand=0):
1246
1253
"Rotate image. Angle given as degrees counter-clockwise."
1257
angle = -angle * math.pi / 180
1259
math.cos(angle), math.sin(angle), 0.0,
1260
-math.sin(angle), math.cos(angle), 0.0
1262
def transform(x, y, (a, b, c, d, e, f)=matrix):
1263
return a*x + b*y + c, d*x + e*y + f
1265
# calculate output size
1269
for x, y in ((0, 0), (w, 0), (w, h), (0, h)):
1270
x, y = transform(x, y)
1273
w = int(math.ceil(max(xx)) - math.floor(min(xx)))
1274
h = int(math.ceil(max(yy)) - math.floor(min(yy)))
1277
x, y = transform(w / 2.0, h / 2.0)
1278
matrix[2] = self.size[0] / 2.0 - x
1279
matrix[5] = self.size[1] / 2.0 - y
1281
return self.transform((w, h), AFFINE, matrix)
1248
1283
if resample not in (NEAREST, BILINEAR, BICUBIC):
1249
1284
raise ValueError("unknown resampling filter")
1939
1972
file = image._dump(format=format)
1941
1974
if os.name == "nt":
1942
os.system("%s %s" % (command, file))
1943
# FIXME: this leaves temporary files around...
1975
command = "start /wait %s && del /f %s" % (file, file)
1944
1976
elif sys.platform == "darwin":
1945
1977
# on darwin open returns immediately resulting in the temp
1946
1978
# file removal while app is opening
1947
os.system("(%s %s; sleep 20; rm -f %s)&" % (command, file, file))
1979
command = "(%s %s; sleep 20; rm -f %s)&" % (command, file, file)
1949
os.system("(%s %s; rm -f %s)&" % (command, file, file))
1981
command = "(%s %s; rm -f %s)&" % (command, file, file)