Example #1
0
    def crop(self, p, width, height):
        """Crop the image starting at upper left point `p' and width `w',
        height `h'.
        """
        new = gd.createImage(width, height, self.truecolor())
	if not self.truecolor() and self.transparent() != -1:
	    r, g, b, a = xRGBA(self.get_color(self.transparent()))
	    trans = new.colorAllocate(r, g, b, a)
	    new.colorTransparent(trans)
	    new.rectangle(0, 0, width, height, trans, 1)
	new.copy(self.m_image, 0, 0, p[0], p[1], width, height)
	self.m_image = new
Example #2
0
    def resize(self, width, height, smooth=1):
	"""Resize the image to `width' times `height' pixels.
        
        If `smooth' is nonzero, the image is smoothly interpolated.
	"""
	new = gd.createImage(width, height, self.truecolor())
	if not self.truecolor() and self.transparent() != -1:
	    r, g, b, a = xRGBA(self.get_color(self.transparent()))
	    trans = new.colorAllocate(r, g, b, a)
	    new.colorTransparent(trans)
	    new.rectangle(0, 0, width, height, trans, 1)
	new.copy(self.m_image, 0, 0, 0, 0, width, height, self.width(),
		 self.height(), smooth)
	self.m_image = new
Example #3
0
    def convert_truecolor(self, bgcolor=None):
	"""Convert an indexed color image to a truecolor one.
        
        If the indexed color image has a transparent background, it is kept
        by default.  But because there is poor support amongst web browsers
        for truecolor images with transparency, the `bgcolor' parameter
        allows you to override the background color.
	"""
	if self.truecolor():
	    return
	new = gd.createImage(self.width(), self.height(), 1)
	if bgcolor is None:
	    if self.transparent() != -1:
		r, g, b, a = xRGBA(self.get_color(self.transparent()))
		bgcolor = RGBA(r, g, b, gd.AlphaTransparent)
	if bgcolor:
	    new.rectangle(0, 0, self.width(), self.height(), bgcolor, 1)
	new.copy(self.m_image, 0, 0, 0, 0, self.width(), self.height())
	self.m_image = new
Example #4
0
    def new(cls, width, height, truecolor=1):
	"""Create a new image of resolution `width' times `height' pixels
	and of color mode `truecolor'.
	"""
	image = gd.createImage(width, height, truecolor)
	return cls(image)