Converting PHP Code to Coldfusion

I'm trying to implement a proxy for html2canvas ( in Coldfusion.

I've found a script created in PHP but I have no experience and not much time to replicate the code in CF.

I did the following as of now in CF

What I'm not sure is the code (PHP file) in line 22

    $re_encoded_image = sprintf(
            'data:%s;base64,%s', $file_details["mime_type"], base64_encode($file_details["data"])

    print "{$callback}(" . json_encode($re_encoded_image) . ")";

Open in new window

I know that SerializeJSON = json_encode in PHP

<cfhttp url="#url.url#"    
<cfset img = resp.fileContent />
<cfcontent type="application/javascript" />

Open in new window

Link to PHP file (

I've also attached the php file.
Who is Participating?
_agx_Connect With a Mentor Commented:
I'm not real familiar with php, but looks like that part just returns a string with a base64 encoded image and mime type.


If your cfhttp call returns a binary image, just grab the mime type and convert the fileContent to base64. Not tested, but something along these lines ...

     <!--- check for errors first obviously ...--->
     <cfset str = "data:"& resp.mimeType &";base64,"& binaryEncode(resp.fileContent, "base64")>

Then run it through SerializeJSON. But don't forget the brackets {} and parenthesis when you create the final string. The output should look something like this
     { your_callback_name_here }( your_json_string_here );
ymorin007Author Commented:
Thanks a million you are my lifesaver ... It work perfectly.
Great, glad I could help!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.