-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcfimage.cfc
75 lines (57 loc) · 2.08 KB
/
cfimage.cfc
1
2
3
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
<cfcomponent output="false">
<cffunction name="init" access="public" returntype="any" output="no">
<cfreturn this>
</cffunction>
<cffunction name="read" access="public" returntype="struct" output="no">
<cfargument name="source" type="string" required="yes">
<cfset var sResult = StructNew()>
<cfset var key = "">
<cfset var image = 0>
<cfimage action="read" source="#arguments.source#" name="image">
<cfset sResult.width = image.width>
<cfset sResult.height = image.height>
<cfset sResult.source = image.source>
<cfreturn sResult>
</cffunction>
<cffunction name="scaleToFit" access="public" returntype="void" output="no">
<cfargument name="source" type="string" required="yes">
<cfargument name="quality" type="string" required="yes">
<cfargument name="width" type="string" required="yes">
<cfargument name="height" type="string" required="yes">
<cfset var myImage = 0>
<cfset var filename = ListLast(ListLast(arguments.source,"\"),"/")>
<cfimage action="read" source="#arguments.source#" name="myImage">
<!--- <cfdump var="#arguments#">
<cfabort> --->
<!--- Scale image to fit --->
<cfset ImageScaleToFit(myImage,arguments.width,arguments.height)>
<!--- <cfset ImageWrite(myImage,filename,arguments.quality)> --->
<cfimage
action="write"
source="#myImage#"
destination="#filename#"
overwrite="true"
quality="#arguments.quality#"
>
</cffunction>
<cffunction name="onMissingMethod" access="public" returntype="any" output="no">
<cfset var fList = StructKeyList(GetFunctionList())>
<cfset var result = 0>
<cfset var method = arguments.missingMethodName>
<cfset var args = arguments.missingMethodArguments>
<cfset var cfimage = 0>
<cfset var namedActions = "border,convert,read,resize,rotate">
<cfif ListFindNoCase(fList,method)>
<cfset result = Evaluate("#method#(argumentCollection=args)")>
<cfelse>
<cfset args.action = method>
<cfif ListFindNoCase(namedActions,method)>
<cfset args.name = "result">
</cfif>
<cfimage attributecollection="#args#">
</cfif>
<cfif isDefined("result")>
<cfreturn result>
</cfif>
</cffunction>
</cfcomponent>