Created
July 30, 2015 09:57
-
-
Save mjhagen/a6560875243aadc9d0e8 to your computer and use it in GitHub Desktop.
CFML Better Image Resize
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfcomponent> | |
<cfset this.jl = new javaloader.JavaLoader( ['#request.site.s_ANCHOR_PATH#/lib/java/java-image-scaling-0.8.5.jar'] ) /> | |
<cffunction name="resizeImage" access="remote" returnType="string" returnFormat="plain"> | |
<cfargument name="image" required="true" /> | |
<cfargument name="width" required="true" /> | |
<cfargument name="height" required="true" /> | |
<cfset var originalImageLocation = this.forcedBasePath & arguments.image /> | |
<cfset var originalImageDir = getDirectoryFromPath( originalImageLocation ) /> | |
<cfset var originalImageFile = reverse( listRest( reverse( getFileFromPath( originalImageLocation )), '.' )) /> | |
<cfset var resampleOp = this.jl.create( 'com.mortennobel.imagescaling.ResampleOp' ).init( | |
javaCast( "int", arguments.width ), | |
javaCast( "int", arguments.height ) | |
).filter( imageGetBufferedImage( imageRead( originalImageLocation )), javaCast( "null", 0 )) /> | |
<cfset imageWrite( imageNew( resampleOp ), originalImageDir & '#originalImageFile#_#arguments.width#x#arguments.height#.jpg', .8, true ) /> | |
<cfreturn ls( originalImageDir ) /> | |
</cffunction> | |
</cfcomponent> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment