幾天前,我正在尋找方式使用我的自定義PHP的WordPress的網站,我在這裏找到答案:How to add a php page to Wordpress。
試過幾個例子,它們對每個例子都很好。但後來我想更進一步,並在wordpress頁面中使用PHP圖像處理。它(只使用此代碼)在普通的PHP網站的作品,但是當我嘗試在worpress使用它我得到錯誤:添加PHP文件到wordpress - Header()已經發送
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.
所以看起來像get_header();這在某種程度上是「問題」。
嘗試使用ob_start(),刷新,乾淨等,但後來我得到我想要的圖像,沒有worpress網站加載。我用盡了選項,其中沒有解決了我的問題。
我的問題是:如何發送這個頭,使其工作的辯論,因爲沒有它,我看到一些奇怪的符號代替PNG圖片(像我會用記事本打開PNG圖片)
任何幫助表示讚賞。
不幸的是,我不是這種情況。那麼,我的文件中沒有空格/換行符,但是不可能搜索所有的wordpress文件。 – Kedor 2012-07-06 09:47:24