Skip to main content
Known Participant
February 28, 2024
Answered

Adding dynamic QR code generator to ColdFusion program

  • February 28, 2024
  • 1 reply
  • 2742 views

When I took over the care of a CF intranet site, the Google chart API was being used to generate QR codes that are on employee badges; this won't be working for much longer and I need to find a replacement.  

 

<cfimage source="#myImage#" 
destination="c:/workgroups/webdata/badgecards/#BadgPhotoName#" 
action="write" 
overwrite="Yes">
 
result="qrcode" 
getasbinary="yes">
 
<cfimage action="write" 
destination="c:/workgroups/webdata/badgecards/qr/#Replace(BadgPhotoName,'.jpg','.png','All')#"  
source="#qrcode.filecontent#" 
overwrite="yes">
 
This is what the code looks like I found a new generator, but I haven't been able to get it to work correctly.  The generator that I was looking at is goqr.me/api, but I was wondering if Adobe has something like that, that I could use?
This topic has been closed for replies.
Correct answer BKBK

Thank you - I'll give that a try.


Addendum: for the sake of rigour, I would add a try/catch to catch errors that arise when the download does not have image content-type

<cftry>
	<!--- Convert the binary to an image in ColdFusion --->
	<cfimage source="#downloadedBinary#" name="downloadedImage">
	
	<cfif isImage(downloadedImage)> 
		<!--- Use, preferably, replaceNoCase: think Jpg, JPG, jpg --->    
		<cfset jpg_to_png=replaceNoCase(BadgPhotoName,'.jpg','.png','all')>
	    <cfimage action="write" source="#downloadedImage#" destination="c:/workgroups/webdata/badgecards/qr/#jpg_to_png#">
	</cfif>
<cfcatch type="any">
	<!--- Handle any errors --->
</cfcatch>
</cftry>

 

1 reply

BKBK
Community Expert
Community Expert
March 24, 2024

No, there are currently no facilities for generating QR codes in ColdFusion. You have to use a third-party QR code generator. Google will show you some, such as CFQRCode.

srouse72Author
Known Participant
March 26, 2024

I found a QR code generator to use, and it has worked great since I added it - until Sunday and not it isn't working.  I copied the URL into a browser to make sure that the generator was working and it is, but the codes aren't printing on the badge card.

<cfhttp method="get" url="https://api.qrserver.com/v1/create-qr-code/?size=150x150&data='https://www.ohrc.org/binkley/badgeCard/PDFs/#replace(badgPhotoName, '.jpg', '.pdf', 'All')#'" getasbinary="yes" charset="utf-8"/>
   
    <cfif isImageFile("#cfhttp.fileContent#")>
        <cfset myImage=imageNew("#cfhttp.fileContent#")>
        <cfset isImage ("#cfhttp.fileContent#")>
        <cfimage action="write" source="#cfhttp.fileContent#" destination="c:/workgroups/webdata/badgecards/qr/#Replace(BadgPhotoName,'.jpg','.png','All')#">
    </cfif>
This is the code that is suddenly not working.  Any suggestions would be greatly appreciated.
BKBK
Community Expert
Community Expert
March 26, 2024

Suggestion as a replacement for the code below the cfhttp tag:

<cfset downloadedBinary=cfhttp.fileContent>
<!--- Convert the binary to an image in ColdFusion --->
<cfimage source="#downloadedBinary#" name="downloadedImage">

<cfif isImage(downloadedImage)> 
	<!--- Use, preferably, replaceNoCase: think Jpg, JPG, jpg --->    
	<cfset jpg_to_png=replaceNoCase(BadgPhotoName,'.jpg','.png','all')>
    <cfimage action="write" source="#downloadedImage#" destination="c:/workgroups/webdata/badgecards/qr/#jpg_to_png#">
</cfif>