1

here is my canvas image in a page called 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>

i want to get this image as an actuall image in the other pages .... basically i want to able to do this in otherpage.php

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

this image dynamically changes from time to time .. so i dont want to save it ... just want to show it as it is in another pages without canvas

4

1 回答 1

0

您不能在 PHP 文件中使用并使用,canvas调用该 PHPimg

  • Canvas 使用 Javascript PHP 文件头必须设置为
  • 图像/png 或图像/jpgheader( "Content-type: image/png" );

“iframe 没有问题”好的!

您唯一的解决方案是使用PHP 图像PHP: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 
?>

索引.html

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

请参阅这些资源:

于 2013-09-27T07:53:39.690 回答