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
Re: [Image-SIG] pattern fill
by Andre Kuehne other posts by this author
Aug 23 2004 4:09PM messages near this date
[Image-SIG] pattern fill | [Image-SIG] Re: pattern fill
Hi

Here is a code snippet i wrote some time ago for filling a region (box)
of an image (img) with a tile (src):


def fillRegion(img, box, src):
    (left,top,right,bottom) = box
    (srcWidth, srcHeight) = src.size
    y = top
    remY = (bottom-top)
    while remY >  0:
        x = left
        remX = (right-left)
        while remX >  0:
            if remX > = srcWidth:
                if remY > = srcHeight:
                    alphaPaste(img,src,(x,y))
                    putWidth = srcWidth
                    putHeight = srcHeight
                else:
                    frac = src.crop((0, 0, srcWidth, remY))
                    alphaPaste(img,frac,(x,y))
                    putWidth = srcWidth
                    putHeight = remY
            else:
                if remY > = srcHeight:
                    frac = src.crop((0, 0, remX, srcHeight))
                    alphaPaste(img,frac,(x,y))
                    putWidth = remX
                    putHeight = srcHeight
                else:
                    frac = src.crop((0, 0, remX, remY))
                    alphaPaste(img,frac,(x,y))
                    putWidth = remX
                    putHeight = remY
            x += putWidth
            remX -= putWidth
        y += putHeight
        remY -= putHeight

def alphaPaste(dst, src, box):
    if src.mode == "RGBA":
        dst.paste(src, box, src)
    else:
        dst.paste(src, box)


If someone has a more elegant way to do this, it would be nice to see.

regards

-- 
     _   _
_/\_| |_( )_
Andre Kuehne

_______________________________________________
Image-SIG maillist  -  Image-SIG@[...].org
http://mail.python.org/mailman/listinfo/image-sig
Thread:

Andre Kuehne
Fredrik Lundh

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