CFImage Effects

ColdFusion

entryImageI know that Foundeo has created an Image Effects CFC that can do image gradients and the "iTunes" mirroring effect, but while I was sitting at home today with a bit of a cold, I just had to make this effect myself. Unfortunately, I figured out in the process that I needed a gradient effect while I was creating this function, so they are both here. All in all, not too hard. I realized that the iTunesMirror function should be tacking on a boarder to the non-reflection, but I think it works well enough as is.

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
Thanks for the example, this is great!
# Posted By KJ | 12/11/07 11:51 AM

Testing YouTube Video content.

If it proves too annoying, I'll get rid of it.

Calendar

Sun Mon Tue Wed Thu Fri Sat
    123
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31

Subscribe

Enter your email address to subscribe to this blog.

Archives By Subject

Ajax (1) [RSS]
BlogCFC (2) [RSS]
CF8 (8) [RSS]
cfimage (7) [RSS]
ColdFusion (13) [RSS]
css (5) [RSS]
frameworks (8) [RSS]
Funny (2) [RSS]
Google (1) [RSS]
IIS (1) [RSS]
Java in ColdFusion (4) [RSS]
javascript (6) [RSS]
Licensing (2) [RSS]
Model Glue (2) [RSS]
Projects (3) [RSS]
Prototype (2) [RSS]
Spry (1) [RSS]
SQL Server (2) [RSS]
User Interface Design (1) [RSS]
Web Services (1) [RSS]

RSS