使用php创建图像并在joomla模板中显示它(Create image with php and show it in joomla template)

系统教程 行业动态 更新时间:2024-06-14 16:57:18
使用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();?>'>

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

I have a simple function in a class:

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

In model file:

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

view.html.php file:

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

I call this function in a joomla template with giving src attribute of image tag such manner:

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

but in spite of I get the image, I can see the binary code of the image in the browser. What is the error? Many thanks

最满意答案

您的creimage方法正在发送实际的图像数据,这些数据是您在src=''属性中所固定的,这将无效。

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

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

然后在那里创建一个PHP脚本,使用适当的标头发送图像数据。

Your creimage method is sending out the actual image data, which you are sticking inside of your src='' attribute, that won't work.

You need to put a URL in the src attribute:

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

Then create a PHP script there that sends out the image data with the appropriate header.

更多推荐

image,function,php,电脑培训,计算机培训,IT培训"/> <meta name="descriptio

本文发布于:2023-04-12 20:17:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/2e7fc5e762eb6dcf537d5bdf72e3e16c.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:并在   图像   模板   joomla   php

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!