ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> image-sig
image-sig
[PYTHON IMAGE-SIG] The crop method doesn't work properly for palette images
by Fredrik Lundh other posts by this author
Jan 18 1997 6:27AM messages near this date
[PYTHON IMAGE-SIG] PIL 0.2b4 doesn't handle FLC animations | [PYTHON IMAGE-SIG] The Image.new() function doesn't initialize the new image
A last-minute workaround to stop "crop" from crashing if the box
extended outside the source image, messed things up when working with
palette images.  To fix this, replace the "crop" method in Image.py
with the following code:

    def crop(self, box = None):
        "Crop region from image"

	self.load()
	if box == None:
	    return self.copy()

	# the C implementation of crop is broken, so we implement
	# it by pasting into empty image instead.

	# im = self.im.crop(box)

	size = box[2]-box[0], box[3]-box[1]

	im = core.new(self.mode, size)
	im.paste(self.im, (-box[0], -box[1],
		 self.size[0]-box[0],
		 self.size[1]-box[1]))

	imOut = self._makeself(im)

	if imOut.mode == "P":
	    imOut.im.putpalette("RGB", self.im.getpalette("RGB"))

	return imOut

In future versions, this will be fixed in the C implementation,
reducing the above code to a simple call to self.im.crop() instead.

Regards	/F

_______________
IMAGE-SIG - SIG on Image Processing with Python

send messages to: image-sig@[...].org
administrivia to: image-sig-request@[...].org
_______________

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved