将PHP文件添加到wordpress-Header()已发送
几天前,我在wordpress网站上寻找使用自定义php的方法,我在这里找到了答案:将PHP文件添加到wordpress-Header()已发送,php,wordpress,gd,Php,Wordpress,Gd,几天前,我在wordpress网站上寻找使用自定义php的方法,我在这里找到了答案:尝试了几个例子,每个例子都很有效。但后来我想更进一步,在像这样添加的wordpress页面中使用PHP图像处理。它在普通php站点上工作(仅使用此代码),但当我尝试在worpress中使用它时,我得到错误: Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\w
尝试了几个例子,每个例子都很有效。但后来我想更进一步,在像这样添加的wordpress页面中使用PHP图像处理。它在普通php站点上工作(仅使用此代码),但当我尝试在worpress中使用它时,我得到错误:
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\wordpress\wp-content\themes\twentyeleven\header.php:13) in C:\xampp\htdocs\wordpress\wp-content\themes\twentyeleven\mynewsite.php on line 26
我尝试使用的代码是:
<?php
$dest = imagecreatefrompng('image1.png');
$src = imagecreatefromjpeg('image2.jpg');
imagealphablending($dest, false);
imagesavealpha($dest, true);
imagecopymerge($dest, $src, 10, 9, 0, 0, 181, 180, 100); //putting one image on top of other
header('Content-Type: image/png');
imagepng($dest);
imagedestroy($dest);
imagedestroy($src);
?>
我知道问题是我正在尝试将标题发送到这里,但我不知道如何解决它。我试着把这个头移到文件的顶部,但整个worpress站点并没有加载
header('Content-Type: image/png');
get_header(); //<-- part of wordpress template, cant get rid of it, cuz it ruins whole site look.
header('Content-Type:image/png');
获取_头()// 当我在关闭php标记“?>”后有一个空格/换行符时,我遇到了这个问题,我从所有文件中删除了它,它对我起了作用。非常奇怪,但它确实有效。当我在关闭php标记“?>”后有一个空格/换行符时,我遇到了这个问题。我从所有文件中删除了它,它对我有效。很奇怪,但它奏效了。好的,找到了解决办法。发布答案,因为它可能对将来的其他人有用
因此,我将使用简单的词语,这让我明白了这一点。
header('Content-Type:image/png')代码>使整个网站被“视为图像”。因此,当我甚至找到了在WordPress文件中放置标题的位置时,它仍然没有显示任何结果。要解决这个问题,只需创建另一个名为image.php
的文件,并将PHPGD代码放在那里
$dest = imagecreatefrompng('image1.png');
$src = imagecreatefromjpeg('image2.jpg');
imagealphablending($dest, false);
imagesavealpha($dest, true);
imagecopymerge($dest, $src, 10, 9, 0, 0, 181, 180, 100); //putting one image on top of other
header('Content-Type: image/png');
imagepng($dest);
imagedestroy($dest);
imagedestroy($src);
当然,在
标签和WordPress页面中,您可以使用
来显示它。这将消除所有标题错误,还将显示此PHP代码已创建的图像。好的,找到了解决方案。发布答案,因为它可能对将来的其他人有用
因此,我将使用简单的词语,这让我明白了这一点。
header('Content-Type:image/png')代码>使整个网站被“视为图像”。因此,当我甚至找到了在WordPress文件中放置标题的位置时,它仍然没有显示任何结果。要解决这个问题,只需创建另一个名为image.php
的文件,并将PHPGD代码放在那里
$dest = imagecreatefrompng('image1.png');
$src = imagecreatefromjpeg('image2.jpg');
imagealphablending($dest, false);
imagesavealpha($dest, true);
imagecopymerge($dest, $src, 10, 9, 0, 0, 181, 180, 100); //putting one image on top of other
header('Content-Type: image/png');
imagepng($dest);
imagedestroy($dest);
imagedestroy($src);
当然,在
标签和WordPress页面中,您可以使用
来显示它。这将消除所有标题错误,还将显示此PHP代码已创建的图像。不幸的是,我不是这样。嗯,我的文件中没有空格/换行符,但不可能通过所有wordpress文件进行搜索。不幸的是,我的情况并非如此。嗯,我的文件中没有空格/换行符,但不可能通过所有wordpress文件进行搜索。