![]()
As you may have known, Foundeo has created an Image Effects CFC that can generate image gradients, reflection, drop shadows, and some more cool effects by taking advantage of the new image features in ColdFusion 8.
Some people have been trying to replicate some of the functions this package has, especially the gradients, reflection and rounded corners functions. John Hartmann did an excellent job in replicating the reflect() and gradientMask() functions.
Jeff Coughlin also started building a CFImage Effects Plugin for FarCry based off of John Hartmann's functions. His Plugin has code to replicate the rounded corners.
Now, lets get into the code...
I went ahead and combined the reflect() and gradientMask() functions I got from John Hartmann with the roundCorners() function I got from Jeff Coughlin.
Here is my imageEffects.cfc:
var imgCopy = arguments.objImage;
var strInfo = ImageInfo(imgCopy);
var imgNew = ImageNew("", strInfo.width, strInfo.height+arguments.reflectionHeight, "argb", arguments.backgroundColor);
var imgPart = "";
// Make sure the reflection hieght is not greater than the height of the image
if (arguments.reflectionHeight gt strInfo.height){
arguments.reflectionHeight = strInfo.height;
}
if (arguments.antialiasing is true){
imageSetAntialiasing(imgNew,"on");
}
imageFlip(imgCopy, "vertical");
imgPart = ImageCopy(imgCopy, 0, 0, strInfo.width, arguments.reflectionHeight);
gradientMask(objImage=imgPart, backgroundColor=arguments.backgroundColor);
ImageFlip(imgCopy, "vertical");
ImagePaste(imgNew, arguments.objImage, 0, 0);
ImageSetDrawingTransparency(imgNew, 100-opacity);
ImagePaste(imgNew, imgPart, 0, strInfo.height);
return imgNew;
var strInfo = ImageInfo(arguments.objImage);
var iInc = 50/strInfo.height;
var i = 0;
if (arguments.antialiasing is true){
imageSetAntialiasing(arguments.objImage,"on");
}
ImageFlip(arguments.objImage, "vertical");
ImageSetDrawingColor(arguments.objImage, arguments.backgroundColor);
for (i = 0; i lte (strInfo.height-1); i = i + 1) {
ImageSetDrawingTransparency(arguments.objImage, round(iInc*i*2));
ImageDrawLine(arguments.objImage, 0, i, strInfo.width, i);
}
ImageFlip(arguments.objImage, "vertical");
return arguments.objImage;
And here is my image.cfm:
<!--- initialize imageEffects.cfc --->
<!--- create image object --->
<!--- round image corners --->
<!--- add reflection to image --->
<!--- display image --->
Here is the image before the process:
And here is the resulting image:
Pretty nice I must say...
You can see a working demo of it here with black and white backgrounds: http://labs.dcfusion.com/image-test/roundCorners.cfm.
Recent Comments