- Html to canvas php
- Saved searches
- Use saved searches to filter your results more quickly
- License
- brcontainer/html2canvas-php-proxy
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- Saved searches
- Use saved searches to filter your results more quickly
- adjdred/html2canvas-proxy-php
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
Html to canvas php
This script allows you to use html2canvas.js with different servers, ports and protocols (http, https), preventing to occur «tainted» when exporting the for image.
Others scripting language
You do not use PHP, but need html2canvas working with proxy, see other proxies:
When adding an image that belongs to another domain in 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
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.
I ask you to follow me or «star» my repository to track updates
Run script in Cross-domain (data URI scheme)
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:
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) |
> html> head> meta charset pl-s">utf-8"> title>html2canvas php proxytitle> script src pl-s">html2canvas.js">script> script> // (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 pl-s">google maps static" src pl-s">http://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&zoom=12&size=800x600&maptype=roadmap&sensor=false"> p> body> html>
If you have any problems with the script recommend to analyze the log use the Web Console from your browser:
An alternative is to diagnose problems accessing the link directly:
Replace [DOMAIN] by your domain (eg. 127.0.0.1) and replace [PATH] by your project folder (eg. project-1/test), something like:
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
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
License
brcontainer/html2canvas-php-proxy
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
This script allows you to use html2canvas.js with different servers, ports and protocols (http, https), preventing to occur «tainted» when exporting the for image.
Others scripting language
You do not use PHP, but need html2canvas working with proxy, see other proxies:
When adding an image that belongs to another domain in 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
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.
I ask you to follow me or «star» my repository to track updates
Run script in Cross-domain (data URI scheme)
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:
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) |
> html> head> meta charset pl-s">utf-8"> title>html2canvas php proxytitle> script src pl-s">html2canvas.js">script> script> // (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 pl-s">google maps static" src pl-s">http://maps.googleapis.com/maps/api/staticmap?center=40.714728,-73.998672&zoom=12&size=800x600&maptype=roadmap&sensor=false"> p> body> html>
If you have any problems with the script recommend to analyze the log use the Web Console from your browser:
An alternative is to diagnose problems accessing the link directly:
Replace [DOMAIN] by your domain (eg. 127.0.0.1) and replace [PATH] by your project folder (eg. project-1/test), something like:
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
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
basic php proxy for html2canvas
adjdred/html2canvas-proxy-php
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
basic php proxy for html2canvas using curl
simply download proxy.php file and point html2canvas proxy option to the file.
##PHP Requirements You will need to make sure you have the below extensions enabled in your php.ini file.