0

请查看演示站点

http://jsfiddle.net/Alidad/fexGj/

该演示称为“图像标题”,我的下一步是将文本和图像作为一组转换为图像,以便我可以单击鼠标右键进行复制和粘贴。

但是,有 PHP 代码允许我从文本转换为图像,但我很难弄清楚如何将“图像标题”(演示)转换为 HTML!

这是示例 PHP 代码,但我不知道如何组合它!

<?php
// Create a 100*30 image
$im = imagecreate(100, 30);

// White background and blue text
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 255);

// Write the string at the top left
imagestring($im, 5, 0, 0, 'Hello world!', $textcolor);

// Output the image
header('Content-type: image/png');

imagepng($im);
imagedestroy($im);
?>

请帮助我如何将其转换为 jQuery 代码中的图像!

4

1 回答 1

1

最简单的方法可能就是这样做:

// index.html
<img src="render_image.php?text=Hello World" />

接着:

// render_image.php
<?php
// Create a 100*30 image
$im = imagecreate(100, 30);

// White background and blue text
$bg = imagecolorallocate($im, 255, 255, 255);
$textcolor = imagecolorallocate($im, 0, 0, 255);

// Write the string at the top left
imagestring($im, 5, 0, 0, $_GET['text'], $textcolor);

// Output the image
header('Content-type: image/png');

imagepng($im);
imagedestroy($im);
?>

使用它对您的 javascript 代码稍作修改应该可以工作。

有关使用 $_GET 变量的更多信息:http: //php.net/manual/en/reserved.variables.get.php

于 2012-12-13T04:52:11.727 回答