繁体   English   中英

使用php创建图像并将其显示在joomla模板中

[英]Create image with php and show it in joomla template

我在课堂上有一个简单的功能:

<?php>class cre
{
    function creimage()
        {
             header("Content-type: image/gif");
             $im = imagecreate (100, 50);
             imagegif($im);
             imagedestroy($im);
        }
};?>

在模型文件中:

<?php class mymodel extends JModel
{
    var myclass;
    function __construct()
        {
            myclass = new cre();
        }
    function getMyclass()
        {
            return $this->myclass;
        }
};?>

view.html.php文件:

<?php class myview extends JView
{
    function display($tpl = null)
         {
             $myclass = & $this->get('Myclass');
             parent::display($tpl);
         }
};?>

我在joomla模板中调用此函数,并通过以下方式提供了image标签的src属性:

<img src='<?php echo $this->myclass->creimage();?>'>

但是尽管我得到了图像,但仍可以在浏览器中看到图像的二进制代码。 有什么错误? 非常感谢

您的creimage方法正在发送实际的图像数据,您将其粘贴到src=''属性中,该数据将不起作用。

您需要在src属性中放置一个URL:

<img src='/path/to/imagescript.php'>

然后在此处创建一个PHP脚本,以发送带有适当标头的图像数据。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM