-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<cfscript> | ||
generator = new res.qrcodes.QrCodeGenerator(); | ||
generator.generateQrCode( "hello world" ); | ||
</cfscript> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Simple wrapper to Java library for generating QR Codes | ||
* | ||
* @autodoc | ||
* @singleton | ||
* | ||
*/ | ||
component { | ||
|
||
public any function init() { | ||
_setupLibPath( ); | ||
|
||
return this; | ||
} | ||
|
||
// PUBLIC API | ||
public binary function generateQrCode( required string input, numeric size=125, string imageType="gif" ) { | ||
var qrCode = CreateObject( "java", "net.glxn.qrgen.javase.QRCode", _getLibPath() ); | ||
var binary = qrCode.from( arguments.input ) | ||
.to( _getImageTypeConstant( arguments.imageType ) ) | ||
.withSize( arguments.size, arguments.size ) | ||
.stream() | ||
.toByteArray(); | ||
return binary; | ||
} | ||
|
||
|
||
|
||
// PRIVATE HELPERS | ||
private void function _setupLibPath() { | ||
var dir = GetDirectoryFromPath( GetCurrentTemplatePath() ) & "/lib"; | ||
var jarFiles = DirectoryList( dir, true, "path" ); | ||
|
||
_setLibPath( jarFiles ); | ||
} | ||
|
||
private string function _getImageTypeConstant( required string imageType ) { | ||
var imageTypes = CreateObject( "java", "net.glxn.qrgen.core.image.ImageType", _getLibPath() ); | ||
|
||
switch( arguments.imageType ) { | ||
case "jpg": | ||
return imageTypes.JPG; | ||
case "png": | ||
return imageTypes.PNG; | ||
default: | ||
return imageTypes.GIF; | ||
} | ||
} | ||
|
||
// ACCESSORS | ||
private array function _getLibPath() { | ||
return _libPath; | ||
} | ||
private void function _setLibPath( required array libPath ) { | ||
_libPath = arguments.libPath; | ||
} | ||
|
||
} |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.