Solved

Converting PHP Code to Coldfusion

Posted on 2013-11-01
3
966 Views
Last Modified: 2013-11-01
I'm trying to implement a proxy for html2canvas (http://html2canvas.hertzen.com/) 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#"    
	timeout="45"
    throwonerror="true"
    method="get"
	result="resp">
</cfhttp>
<cfset img = resp.fileContent />
<cfcontent type="application/javascript" />
<cfoutput>#url.callback#("#SerializeJSON(img)#");</cfoutput>

Open in new window



Link to PHP file (https://github.com/adjdred/html2canvas-proxy-php/blob/master/proxy.php)

I've also attached the php file.
0
Comment
Question by:ymorin007
  • 2
3 Comments
 
LVL 52

Accepted Solution

by:
_agx_ earned 500 total points
ID: 39617856
I'm not real familiar with php, but looks like that part just returns a string with a base64 encoded image and mime type.

           data:some_mime_type_here;base64,base_64_encoded_image_here

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 );
0
 

Author Comment

by:ymorin007
ID: 39617906
Thanks a million you are my lifesaver ... It work perfectly.
0
 
LVL 52

Expert Comment

by:_agx_
ID: 39617910
Great, glad I could help!
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question