All Projects → brcontainer → Html2canvas Php Proxy

brcontainer / Html2canvas Php Proxy

Licence: mit
PHP Proxy html2canvas

Projects that are alternatives of or similar to Html2canvas Php Proxy

Jerry
Stars: ✭ 37 (-68.38%)
Mutual labels:  proxy-server
Tor Router
A SOCKS, HTTP and DNS proxy for distributing traffic across multiple instances of Tor
Stars: ✭ 69 (-41.03%)
Mutual labels:  proxy-server
Proxy
C++ TCP Proxy Server
Stars: ✭ 98 (-16.24%)
Mutual labels:  proxy-server
Webshell
Docker container which includes Shellinabox and enables SSH connections to arbitrary (not where installed) servers
Stars: ✭ 40 (-65.81%)
Mutual labels:  proxy-server
Titanium Web Proxy
A cross-platform asynchronous HTTP(S) proxy server in C#.
Stars: ✭ 1,122 (+858.97%)
Mutual labels:  proxy-server
Influx Proxy
A proxy for InfluxDB
Stars: ✭ 73 (-37.61%)
Mutual labels:  proxy-server
Proxy Server
An HTTP proxy server implemented via python socket programming with caching, blacklisting, authentication functionality
Stars: ✭ 24 (-79.49%)
Mutual labels:  proxy-server
Proxyscotch
📡 A simple proxy server created for https://hoppscotch.io
Stars: ✭ 108 (-7.69%)
Mutual labels:  proxy-server
Proxy List
A list of free, public, forward proxy servers. UPDATED DAILY!
Stars: ✭ 1,125 (+861.54%)
Mutual labels:  proxy-server
Pyproxy
HTTP(s) proxy server base on tornado, in one file!
Stars: ✭ 98 (-16.24%)
Mutual labels:  proxy-server
Zazkia
tcp proxy to simulate connection problems
Stars: ✭ 49 (-58.12%)
Mutual labels:  proxy-server
Imager
Image processing proxy
Stars: ✭ 56 (-52.14%)
Mutual labels:  proxy-server
Lightsocks Nodejs
It's a simple socks5 proxy tool which based on lightsocks
Stars: ✭ 79 (-32.48%)
Mutual labels:  proxy-server
Wiremockui
Wiremock UI - Tool for creating mock servers, proxies servers and proxies servers with the option to save the data traffic from an existing API or Site.
Stars: ✭ 38 (-67.52%)
Mutual labels:  proxy-server
Forward Proxy
150 LOC Ruby forward proxy using only standard libraries.
Stars: ✭ 105 (-10.26%)
Mutual labels:  proxy-server
Citadelcore
Cross platform filtering HTTP/S proxy based on .NET Standard 2.0.
Stars: ✭ 28 (-76.07%)
Mutual labels:  proxy-server
Skrop
Image transformation service using libvips, based on Skipper.
Stars: ✭ 71 (-39.32%)
Mutual labels:  proxy-server
Httpproxy
Go HTTP proxy server library
Stars: ✭ 110 (-5.98%)
Mutual labels:  proxy-server
Freeproxy
免费、高速的 V2Ray 代理和订阅。
Stars: ✭ 104 (-11.11%)
Mutual labels:  proxy-server
Delete
(迫于压力,本项目停止维护,请尽快fork代码。1月1日之后删除项目)[免翻墙工具]A free and open-source youtube video proxy script [Written in PHP]
Stars: ✭ 1,316 (+1024.79%)
Mutual labels:  proxy-server

html2canvas-php-proxy

PHP Proxy html2canvas

This script allows you to use html2canvas.js with different servers, ports and protocols (http, https), preventing to occur "tainted" when exporting the <canvas> for image.

Others scripting language

You do not use PHP, but need html2canvas working with proxy, see other proxies:

Problems and solutions

When adding an image that belongs to another domain in <canvas> and after that try to export the canvas for a new image, a security error occurs (actually occurs is a security lock), which can return the error:

SecurityError: DOM Exception 18

Error: An attempt was made to break through the security policy of the user agent.

If using Google Maps (or google maps static) you can get this error in console:

Google Maps API error: MissingKeyMapError

You need get a API Key in: https://developers.google.com/maps/documentation/javascript/get-api-key

If get this error:

Access to Image at 'file:///...' from origin 'null' has been blocked by CORS policy: Invalid response. Origin 'null' is therefore not allowed access.

Means that you are not using an HTTP server, html2canvas does not work over the "file:///" protocol, use Apache, Nginx or IIS with PHP for work.

Follow

I ask you to follow me or "star" my repository to track updates

Run script in Cross-domain (data URI scheme)

(See details: https://github.com/brcontainer/html2canvas-php-proxy/issues/9)

Note: Enable cross-domain in proxy server can consume more memory, but can be faster in execution it performs only one request at the proxy server.

Note: If the file html2canvasproxy.php is in the same domain that your project, you do not need to enable this option.

Note: Disable the "cross-domain" does not mean you will not be able to capture images from different servers, in other words, the "cross-domain" here refers to "html2canvas.js" (not necessarily the javascript file, but the place where runs) and the "html2canvas.php" are in different domains, the "cross-domain" here refers domain.

In some cases you may want to use this html2canvasproxy.php on a specific server, but the "html2canvas.js" and another server, this would cause problems in your project with the security causing failures in execution. In order to use security just set in the html2canvasproxy.php:

Enable data uri scheme for use proxy for all servers:

define('H2CP_DATAURI', true);

Disable data uri scheme:

define('H2CP_DATAURI', false);

Setup

Definition Description
define('H2CP_PATH', 'cache'); Folder where the images are saved
define('H2CP_PERMISSION', 0666); Set forlder permission (use 644 or 666 for remove execution for prevent sploits)
define('H2CP_CACHE', 60 * 5 * 1000); Limit access-control and cache in seconds, define 0/false/null/-1 to not use "http header cache"
define('H2CP_TIMEOUT', 20); Timeout from load Socket
define('H2CP_MAX_LOOP', 10); Configure loop limit for redirects (location header)
define('H2CP_DATAURI', false); Enable use of "data URI scheme"
define('H2CP_PREFER_CURL', true); Prefer curl if avaliable or disable
define('H2CP_SSL_VERIFY_PEER', false); Set false for disable SSL checking or true for enable (require config PHP.INI with curl.cainfo=/path/to/cacert.pem). You can set path manualy like this: define('H2CP_SSL_VERIFY_PEER', '/path/to/cacert.pem');
define('H2CP_ALLOWED_DOMAINS', '*'); * allow all domains, for subdomains use like this *.site.com, for fixed domains use , 'site.com,www.site.com' (string separed by commas)
define('H2CP_ALLOWED_PORTS', '80,443'); Config allowed ports (string separed by commas)

Usage

Note: Requires PHP5+

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>html2canvas php proxy</title>
        <script src="html2canvas.js"></script>
        <script>
        //<![CDATA[
        (function() {
            window.onload = function(){
                html2canvas(document.body, {
                    "logging": true, //Enable log (use Web Console for get Errors and Warnings)
                    "proxy": "html2canvasproxy.php",
                    "onrendered": function (canvas) {
                        var img = new Image();
                        img.onload = function() {
                            img.onload = null;
                            document.body.appendChild(img);
                        };
                        img.onerror = function() {
                            img.onerror = null;
                            if(window.console.log) {
                                window.console.log("Not loaded image from canvas.toDataURL");
                            } else {
                                alert("Not loaded image from canvas.toDataURL");
                            }
                        };
                        img.src = canvas.toDataURL("image/png");
                    }
                });
            };
        })();
        //]]>
        </script>
    </head>
    <body>
        <p>
            <img alt="google maps static" src="http://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&amp;zoom=12&amp;size=800x600&amp;maptype=roadmap&amp;sensor=false">
        </p>
    </body>
</html>

Using Web Console

If you have any problems with the script recommend to analyze the log use the Web Console from your browser:

Get NetWork results:

An alternative is to diagnose problems accessing the link directly:

http://[DOMAIN]/[PATH]/html2canvasproxy.php?url=http%3A%2F%2Fmaps.googleapis.com%2Fmaps%2Fapi%2Fstaticmap%3Fcenter%3D40.714728%2C-73.998672%26zoom%3D12%26size%3D800x600%26maptype%3Droadmap%26sensor%3Dfalse%261&callback=html2canvas_0

Replace [DOMAIN] by your domain (eg. 127.0.0.1) and replace [PATH] by your project folder (eg. project-1/test), something like:

http://localhost/project-1/test/html2canvasproxy.php?url=http%3A%2F%2Fmaps.googleapis.com%2Fmaps%2Fapi%2Fstaticmap%3Fcenter%3D40.714728%2C-73.998672%26zoom%3D12%26size%3D800x600%26maptype%3Droadmap%26sensor%3Dfalse%261&callback=html2canvas_0

Changelog

Changelog moved to https://github.com/brcontainer/html2canvas-php-proxy/blob/master/CHANGELOG.md

Next versions

Details of future versions are being studied, in other words, can happen as can be forsaken ideas. The ideas here are not ready or are not public in the main script, are only suggestions. You can offer suggestions on issues.

  • Etag cache browser for use HTTP 304 (resources are reusable, avoiding unnecessary downloads)
  • Cache from SOCKET, if not specified header cache in SOCKET, then uses settings by DEFINE();
  • Rewrinte script using PSR-4
  • Support to composer
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].