<cffunction
name="TileImage"
access="public"
returntype="any"
output="false"
hint="Takes your ColdFusion image object and tiles the given image over it.">
<cfargument
name="Image"
type="any"
required="true"
hint="The ColdFusion image onto which we are going to tile our graphic."
/>
<cfargument
name="TileImage"
type="any"
required="true"
hint="The image that we are going to tile onto our ColdFusion image."
/>
<cfargument
name="X"
type="numeric"
required="false"
default="0"
hint="The X point at which we are going to start our tiling."
/>
<cfargument
name="Y"
type="numeric"
required="false"
default="0"
hint="The Y point at which we are going to start our tiling."
/>
<cfset var LOCAL = {} />
<cfif NOT IsImage( ARGUMENTS.TileImage )>
<cfimage
action="read"
source="#ARGUMENTS.TileImage#"
name="ARGUMENTS.TileImage"
/>
</cfif>
<cfset LOCAL.ImageDimensions = {
Width = ImageGetWidth( ARGUMENTS.Image ),
Height = ImageGetHeight( ARGUMENTS.Image )
} />
<cfset LOCAL.TileDimensions = {
Width = ImageGetWidth( ARGUMENTS.TileImage ),
Height = ImageGetHeight( ARGUMENTS.TileImage )
} />
<cfset LOCAL.StartCoord = {
X = ARGUMENTS.X,
Y = ARGUMENTS.Y
} />
<cfloop condition="(LOCAL.StartCoord.X GT 0)">
<cfset LOCAL.StartCoord.X -= LOCAL.TileDimensions.Width />
</cfloop>
<cfloop condition="(LOCAL.StartCoord.Y GT 0)">
<cfset LOCAL.StartCoord.Y -= LOCAL.TileDimensions.Height />
</cfloop>
<cfset LOCAL.PasteCoord = StructCopy( LOCAL.StartCoord ) />
<cfloop
index="LOCAL.PasteCoord.Y"
from="#LOCAL.StartCoord.Y#"
to="#LOCAL.ImageDimensions.Height#"
step="#LOCAL.TileDimensions.Height#">
<cfloop
index="LOCAL.PasteCoord.X"
from="#LOCAL.StartCoord.X#"
to="#LOCAL.ImageDimensions.Width#"
step="#LOCAL.TileDimensions.Width#">
<cfset ImagePaste(
ARGUMENTS.Image,
ARGUMENTS.TileImage,
LOCAL.PasteCoord.X,
LOCAL.PasteCoord.Y
) />
</cfloop>
</cfloop>
<cfreturn ARGUMENTS.Image />
</cffunction>