CFImage Effects
- August 14, 2007 8:45 PM
- ColdFusion
- Comments (3)
Gradient Mask
<cffunction name="gradientMask">
<cfargument name="image" type="Any"/>
<cfargument name="color" type="string" required="false" default="black"/>
<cfscript>
var strInfo = ImageInfo(arguments.image);
var iInc = 50/strInfo.height;
var i = 0;
ImageFlip(arguments.image, "vertical");
ImageSetDrawingColor(arguments.image, arguments.color);
for (i = 0; i lte (strInfo.height-1); i = i + 1) {
ImageSetDrawingTransparency(arguments.image, round(iInc*i*2));
ImageDrawLine(arguments.image, 0, i, strInfo.width, i);
}
ImageFlip(arguments.image, "vertical");
return arguments.image;
</cfscript>
</cffunction>
iTunes Mirror
<cffunction name="iTunesMirror">
<cfargument name="image" type="any"/>
<cfargument name="color" type="string" required="false" default="black"/>
<cfscript>
var imgCopy = arguments.image;
var strInfo = ImageInfo(imgCopy);
var imgNew = ImageNew("", strInfo.width, strInfo.height*1.4, "rgb", arguments.color);
var imgPart = "";
ImageFlip(imgCopy, "vertical");
imgPart = ImageCopy(imgCopy, 0, 0, strInfo.width, strInfo.height*.4);
GradientMask(imgPart, arguments.color);
ImageFlip(imgCopy, "vertical");
ImagePaste(imgNew, arguments.image, 0, 0);
ImageSetDrawingTransparency(imgNew, 40);
ImagePaste(imgNew, imgPart, 0, strInfo.height);
return imgNew;
</cfscript>
</cffunction>
Executing Functions
<cfscript>
imgNew = ImageRead("20600678_XXL.jpg");
ImageResize(imgNew, 150, 150);
imgNew = iTunesMirror(imgNew, "white");
</cfscript>
<cfimage action="write" destination="mirror1.jpg" source="#imgNew#" quality="1" overwrite="true">
<cfimage action="writeToBrowser" source="#imgNew#" />
Comments
*we don't need no stinking spam links*
I added a Transpose Level to the function but else it works on vertical, horizontal, 180 degree but it does notwork for 270 degree, here is added a few tweeks:
<cffunction name="gradientMask">
<cfargument name="image" type="Any"/>
<cfargument name="color" type="string" required="false" default="black"/>
<cfargument name="reflection2transposeLevels" type="any" default="vertical" required="yes">
<cfscript>
var strInfo = ImageInfo(arguments.image);
var iInc = 50/strInfo.height;
var i = 0;
ImageFlip(arguments.image, "#arguments.reflection2transposeLevels#");
ImageSetDrawingColor(arguments.image, arguments.color);
for (i = 0; i lte (strInfo.height-1); i = i + 1) {
ImageSetDrawingTransparency(arguments.image, round(iInc*i*2));
ImageDrawLine(arguments.image, 0, i, strInfo.width, i);
}
ImageFlip(arguments.image, "#arguments.reflection2transposeLevels#");
return arguments.image;
</cfscript>
</cffunction>
<cffunction name="MirrorReflection">
<cfargument name="image" type="any"/>
<cfargument name="color" type="string" required="false" default="black"/>
<cfargument name="reflection2transposeLevels" type="any" default="vertical" required="yes">
<cfscript>
var imgCopy = arguments.image;
var strInfo = ImageInfo(imgCopy);
var imgNew = ImageNew("", strInfo.width, strInfo.height*1.4, "rgb", arguments.color);
var imgPart = "";
ImageFlip(imgCopy, "#arguments.reflection2transposeLevels#");
imgPart = ImageCopy(imgCopy, 0, 0, strInfo.width, strInfo.height*.4);
GradientMask(imgPart, arguments.color);
ImageFlip(imgCopy, "#arguments.reflection2transposeLevels#");
ImagePaste(imgNew, arguments.image, 0, 0);
ImageSetDrawingTransparency(imgNew, 40);
ImagePaste(imgNew, imgPart, 0, strInfo.height);
return imgNew;
</cfscript>
</cffunction>