+++ /dev/null
-<cfcomponent name="ImageObject">\r
-<!---\r
- ImageObject.cfc written by Rick Root (rick@webworksllc.com)\r
-\r
- Related Web Sites:\r
- - http://www.opensourcecf.com/imagecfc (home page)\r
-\r
-\r
- This is an object oriented interface to the original\r
- ImageCFC.\r
-\r
- Example Code:\r
-\r
- io = createObject("component","ImageObject");\r
- io.setOption("defaultJpegCompression",95);\r
- io.init("#ExpandPath(".")#/emily.jpg");\r
- io.scaleWidth(500);\r
- io.save("#ExpandPath(".")#/imagex1.jpg");\r
-\r
- io.flipHorizontal();\r
- io.save("#ExpandPath(".")#/imagex2.jpg");\r
- io.revert();\r
- io.filterFastBlur(2,5);\r
- io.save("#ExpandPath(".")#/imagex3.jpg");\r
- io.revert();\r
- io.filterPosterize(32);\r
- io.save("#ExpandPath(".")#/imagex4.jpg");\r
-\r
-\r
- LICENSE\r
- -------\r
- Copyright (c) 2006, Rick Root <rick@webworksllc.com>\r
- All rights reserved.\r
-\r
- Redistribution and use in source and binary forms, with or\r
- without modification, are permitted provided that the\r
- following conditions are met:\r
-\r
- - Redistributions of source code must retain the above\r
- copyright notice, this list of conditions and the\r
- following disclaimer.\r
- - Redistributions in binary form must reproduce the above\r
- copyright notice, this list of conditions and the\r
- following disclaimer in the documentation and/or other\r
- materials provided with the distribution.\r
- - Neither the name of the Webworks, LLC. nor the names of\r
- its contributors may be used to endorse or promote products\r
- derived from this software without specific prior written\r
- permission.\r
-\r
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND\r
- CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,\r
- INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
- MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE\r
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR\r
- CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,\r
- BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;\r
- LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)\r
- HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE\r
- OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS\r
- SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
---->\r
-\r
-<cfset variables.img = "">\r
-<cfset variables.revertimg = "">\r
-<cfset variables.imageCFC = createObject("component","image")>\r
-<cfset variables.imageInfo = structNew()>\r
- <cfset variables.imageInfo.width = 0>\r
- <cfset variables.imageInfo.height = 0>\r
- <cfset variables.imageInfo.colorModel = "">\r
- <cfset variables.imageInfo.colorspace = "">\r
- <cfset variables.imageInfo.objColorModel = "">\r
- <cfset variables.imageInfo.objColorspace = "">\r
- <cfset variables.imageInfo.sampleModel = "">\r
- <cfset variables.imageInfo.imageType = 0>\r
- <cfset variables.imageInfo.misc = "">\r
- <cfset variables.imageInfo.canModify = false>\r
-<cfset variables.imageCFC.setOption("throwonerror",true)>\r
-\r
-<!---\r
-\r
- init(filename) Initialize object from a file.\r
- init(width, height) Initialize with a blank image\r
- init(bufferedImage) Initiailize with an existing object\r
---->\r
-<cffunction name="init" access="public" output="false" returnType="void">\r
- <cfargument name="arg1" type="any" required="yes">\r
- <cfargument name="arg2" type="any" required="no">\r
-\r
- <cfif isDefined("arg2") and isNumeric(arg1) and isNumeric(arg2)>\r
- <cfset arg1 = javacast("int",int(arg1))>\r
- <cfset arg2 = javacast("int",int(arg2))>\r
- <cfset variables.img = createObject("java","java.awt.image.BufferedImage")>\r
- <cfset variables.img.init(arg1,arg2,variables.img.TYPE_INT_RGB)>\r
- <cfelseif arg1.getClass().getName() eq "java.awt.image.BufferedImage">\r
- <cfset variables.img = arg1>\r
- <cfelseif isSimpleValue(arg1) and len(arg1) gt 0>\r
- <cfset imageResults = variables.imageCFC.readImage(arg1, "no")>\r
- <cfset variables.img = imageResults.img>\r
- <cfelse>\r
- <cfthrow message="Object Instantiation Error" detail="You have attempted to initialize ooimage.cfc with invalid arguments. Please consult the documentation for correct initialization arguments.">\r
- </cfif>\r
- <cfif variables.revertimg eq "">\r
- <cfset variables.revertimg = variables.img>\r
- </cfif>\r
- <cfset variables.imageInfo = imageCFC.getImageInfo(variables.img,"")>\r
- <cfreturn>\r
-</cffunction>\r
-\r
-<cffunction name="flipHorizontal" access="public" output="true" returnType="void" hint="Flip an image horizontally.">\r
- <cfset var imageResults = imageCFC.flipHorizontal(variables.img,"","")>\r
- <cfset variables.revertimg = variables.img>\r
- <cfset variables.img = imageResults.img>\r
- <cfset variables.imageInfo = imageCFC.getImageInfo(variables.img,"")>\r
-</cffunction>\r
-\r
-<cffunction name="getImageInfo" access="public" output="true" returntype="struct" hint="Returns image information.">\r
- <cfreturn variables.imageInfo>\r
-</cffunction>\r
-<cffunction name="getImageObject" access="public" output="true" returntype="struct" hint="Returns a java Buffered Image Object.">\r
- <cfreturn variables.img>\r
-</cffunction>\r
-\r
-<cffunction name="flipVertical" access="public" output="true" returntype="void" hint="Flop an image vertically.">\r
- <cfset var imageResults = imageCFC.flipVertical(variables.img,"","")>\r
- <cfset variables.revertimg = variables.img>\r
- <cfset variables.img = imageResults.img>\r
- <cfset variables.imageInfo = imageCFC.getImageInfo(variables.img,"")>\r
-</cffunction>\r
-\r
-<cffunction name="scaleWidth" access="public" output="true" returntype="void" hint="Scale an image to a specific width.">\r
- <cfargument name="newWidth" required="yes" type="numeric">\r
- <cfset var imageResults = imageCFC.scaleWidth(variables.img,"","", newWidth)>\r
- <cfset variables.revertimg = variables.img>\r
- <cfset variables.img = imageResults.img>\r
- <cfset variables.imageInfo = imageCFC.getImageInfo(variables.img,"")>\r
-\r
-</cffunction>\r
-\r
-<cffunction name="scaleHeight" access="public" output="true" returntype="void" hint="Scale an image to a specific height.">\r
- <cfargument name="newHeight" required="yes" type="numeric">\r
- <cfset var imageResults = imageCFC.scaleHeight(variables.img,"","", newHeight)>\r
- <cfset variables.revertimg = variables.img>\r
- <cfset variables.img = imageResults.img>\r
- <cfset variables.imageInfo = imageCFC.getImageInfo(variables.img,"")>\r
-</cffunction>\r
-\r
-<cffunction name="resize" access="public" output="true" returntype="void" hint="Resize an image to a specific width and height.">\r
- <cfargument name="newWidth" required="yes" type="numeric">\r
- <cfargument name="newHeight" required="yes" type="numeric">\r
- <cfargument name="preserveAspect" required="no" type="boolean" default="FALSE">\r
- <cfargument name="cropToExact" required="no" type="boolean" default="FALSE">\r
-\r
- <cfset var imageResults = imageCFC.resize(variables.img,"","",newWidth,newHeight,preserveAspect,cropToExact)>\r
- <cfset variables.revertimg = variables.img>\r
- <cfset variables.img = imageResults.img>\r
- <cfset variables.imageInfo = imageCFC.getImageInfo(variables.img,"")>\r
-</cffunction>\r
-\r
-<cffunction name="crop" access="public" output="true" returntype="void" hint="Crop an image.">\r
- <cfargument name="fromX" required="yes" type="numeric">\r
- <cfargument name="fromY" required="yes" type="numeric">\r
- <cfargument name="newWidth" required="yes" type="numeric">\r
- <cfargument name="newHeight" required="yes" type="numeric">\r
- <cfset var imageResults = imageCFC.crop(variables.img,"","",fromX,fromY,newWidth,newHeight)>\r
- <cfset variables.revertimg = variables.img>\r
- <cfset variables.img = imageResults.img>\r
- <cfset variables.imageInfo = imageCFC.getImageInfo(variables.img,"")>\r
-\r
-</cffunction>\r
-\r
-<cffunction name="rotate" access="public" output="true" returntype="void" hint="Rotate an image (+/-)90, (+/-)180, or (+/-)270 degrees.">\r
- <cfargument name="degrees" required="yes" type="numeric">\r
- <cfset var imageResults = imageCFC.rotate(variables.img,"","",degrees)>\r
- <cfset variables.revertimg = variables.img>\r
- <cfset variables.img = imageResults.img>\r
- <cfset variables.imageInfo = imageCFC.getImageInfo(variables.img,"")>\r
-\r
-</cffunction>\r
-\r
-<cffunction name="setOption" access="public" output="true" returnType="void" hint="Sets values for allowed CFC options.">\r
- <cfargument name="key" type="string" required="yes">\r
- <cfargument name="val" type="string" required="yes">\r
- <cfif lcase(trim(key)) eq "throwonerror">\r
- <cfthrow message="Option Configuration Error" detail="You cannot set the throwOnError option when using ImageObject.cfc">\r
- </cfif>\r
- <cfset imageCFC.setOption(key, val)>\r
-\r
-</cffunction>\r
-\r
-<cffunction name="getOption" access="public" output="true" returnType="any" hint="Returns the current value for the specified CFC option.">\r
- <cfargument name="key" type="string" required="yes">\r
- <cfreturn imageCFC.getOption(key)>\r
-</cffunction>\r
-\r
-<cffunction name="filterFastBlur" access="public" output="true" returntype="void" hint="Internal method used for flipping and flopping images.">\r
- <cfargument name="blurAmount" required="yes" type="numeric">\r
- <cfargument name="iterations" required="yes" type="numeric">\r
- <cfset var imageResults = imageCFC.filterFastBlur(variables.img,"","",blurAmount,iterations)>\r
- <cfset variables.revertimg = variables.img>\r
- <cfset variables.img = imageResults.img>\r
- <cfset variables.imageInfo = imageCFC.getImageInfo(variables.img,"")>\r
-\r
-</cffunction>\r
-\r
-<cffunction name="filterSharpen" access="public" output="true" returntype="void" hint="Internal method used for flipping and flopping images.">\r
- <cfset var imageResults = imageCFC.filterSharpen(variables.img,"","")>\r
- <cfset variables.revertimg = variables.img>\r
- <cfset variables.img = imageResults.img>\r
- <cfset variables.imageInfo = imageCFC.getImageInfo(variables.img,"")>\r
-\r
-</cffunction>\r
-\r
-\r
-<cffunction name="filterPosterize" access="public" output="true" returntype="void" hint="Internal method used for flipping and flopping images.">\r
- <cfargument name="amount" required="yes" type="string">\r
- <cfset var imageResults = imageCFC.filterPosterize(variables.img,"","",amount)>\r
- <cfset variables.revertimg = variables.img>\r
- <cfset variables.img = imageResults.img>\r
- <cfset variables.imageInfo = imageCFC.getImageInfo(variables.img,"")>\r
-</cffunction>\r
-\r
-\r
-<cffunction name="addText" access="public" output="true" returntype="void" hint="Add text to an image.">\r
- <cfargument name="x" required="yes" type="numeric">\r
- <cfargument name="y" required="yes" type="numeric">\r
- <cfargument name="fontDetails" required="yes" type="struct">\r
- <cfargument name="content" required="yes" type="String">\r
- <cfset var imageResults = imageCFC.addText(variables.img,"","",x,y,fontDetails,content)>\r
- <cfset variables.revertimg = variables.img>\r
- <cfset variables.img = imageResults.img>\r
- <cfset variables.imageInfo = imageCFC.getImageInfo(variables.img,"")>\r
-\r
-</cffunction>\r
-\r
-<cffunction name="watermark" access="public" output="false" returnType="void">\r
- <cfargument name="wmImage" required="yes" type="Any">\r
- <cfargument name="alpha" required="yes" type="numeric">\r
- <cfargument name="placeAtX" required="yes" type="numeric">\r
- <cfargument name="placeAtY" required="yes" type="numeric">\r
-\r
- <cfset var imageResults = "">\r
- <cfif isSimpleValue(wmImage)>\r
- <!--- filename or URL --->\r
- <cfset imageResults = imageCFC.watermark(variables.img,"","",wmImage,alpha,placeAtX,placeAtY)>\r
- <cfelse>\r
- <!--- must be a java object --->\r
- <cfset imageResults = imageCFC.watermark(variables.img,wmImage,"","",alpha,placeAtX,placeAtY)>\r
- </cfif>\r
- <cfset variables.revertimg = variables.img>\r
- <cfset variables.img = imageResults.img>\r
- <cfset variables.imageInfo = imageCFC.getImageInfo(variables.img,"")>\r
-\r
-</cffunction>\r
-\r
-<cffunction name="save" access="public" output="false" returnType="void">\r
- <cfargument name="filename" type="string" required="no">\r
- <cfargument name="jpegCompression" type="numeric" required="no">\r
- <cfif isDefined("arguments.jpegCompression") and isNumeric(arguments.jpegCompression)>\r
- <cfset imageCFC.writeImage(filename,variables.img,jpegCompression)>\r
- <cfelse>\r
- <cfset imageCFC.writeImage(filename,variables.img)>\r
- </cfif>\r
-</cffunction>\r
-\r
-<cffunction name="revert" access="public" output="true" returntype="void" hint="Undo the previous manipulation.">\r
- <cfset variables.img = variables.revertimg>\r
- <cfset variables.imageInfo = imageCFC.getImageInfo(variables.img,"")>\r
-</cffunction>\r
-\r
-</cfcomponent>\r