2013-09-26 26 views
1
頁面

的實際圖像是在一個名爲canvas.php代表畫布圖像在這裏等

<html> 
    <body> 
    <style type="text/css"> 
    table 
    { 
    border=5; 
    } 
    </style> 
    <p><canvas id="canvas" style="border:2px solid black;" width="500" height="500"></canvas> 
    <script> 
    var canvas = document.getElementById("canvas"); 
    var ctx = canvas.getContext("2d"); 
    var data = "<svg xmlns='http://www.w3.org/2000/svg' width='200' height='200'>" + 
       "<foreignObject width='100%' height='100%'>" + 
        "<div xmlns='http://www.w3.org/1999/xhtml' style='font-size:40px'>" + 
        "<table><tr><td>HI</td><td>Welcome</td></tr><tr><td>Hello</td><td>World</td></tr> </table>" + 
        "</div>" + 
       "</foreignObject>" + 
       "</svg>"; 
    var DOMURL = self.URL || self.webkitURL || self; 
    var img = new Image(); 
    var svg = new Blob([data], {type: "image/svg+xml;charset=utf-8"}); 
    var url = DOMURL.createObjectURL(svg); 
    img.onload = function() { 
     ctx.drawImage(img, 0, 0); 
     DOMURL.revokeObjectURL(url); 
    }; 
    img.src = url; 
    </script> 
    </body> 
    </html> 

我想這個圖像在其他網頁的實際工作圖像頁面我的畫布圖像....基本上我希望能夠做到這一點的otherpage.php

<img src="www.mysite.com/canvas.php" /> 

這個圖像動態不時改變..所以我不想保存它......只是想表明它,因爲它是在另一頁,而帆布

+0

嘗試使用I幀 – Sablefoste

+0

沒有iframe是沒問題的....如果這行不通,我必須用PHP創建 – max

+0

形象嘛,你不能給一個HTML文檔因爲img元素的src應該很明顯... – CBroe

回答

0

在PHP文件不能使用canvas,並呼籲使用img是PHP,

  • 帆布作品使用Javascript PHP文件頭必須設置爲
  • 圖像/ PNG或圖像/ JPG header("Content-type: image/png");

「iframe無問題」ok!

你唯一的解決辦法是使用PHP imagePHP: imagecreate

創建文件myImg.php

<?php 
header("Content-type: image/png"); // set this php file as png file 
$my_img = imagecreate(200, 200); // image width & height 
$background = imagecolorallocate($my_img, 245,245,245); // set the background color 
$text_colour = imagecolorallocate($my_img, 255,66,121); // text color 
imagestring($my_img, 10, 50, 90, "Hello World", $text_colour); // Our Hello World text! 
imagepng($my_img); // outputs PNG image 
?> 

的index.html

<img src="myImg.php" /> // this will output the image from myImg.php 

請參閱以下資源:

+0

謝謝,我知道如何創建一個圖像與PHP ....事情是我必須創建一個圖像,這是非常非常困難的使用PHP gd lib的html表格... – max