Few days ago i was looking for way to use my custom php on wordpress site and i found answer here: How to add a php page to Wordpress.
Tried few examples and it worked well for each of them. But then i wanted to go further and use PHP image processing in wordpress page added like that. It works on normal php site (using JUST this code), but when i try to use it in worpress i get error:
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
My code i am trying to use is:
<?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);
?>
Well i know the problem is i am trying to send header here, but i dont know how to solve it.
I tried moving this header to top of the file, but then whole worpress site don't load.
header('Content-Type: image/png');
get_header(); //<-- part of wordpress template, cant get rid of it, cuz it ruins whole site look.
So looks like get_header(); is somehow "problem" here.
Tried using ob_start(), flush, clean etc, but then i get the image i want, without worpress site loading. I ran out of options, and non of these solved my problem.
My question is: How to send this header to make it work, cuz without it i see some weird symbols instead of png image (like i would open png image with notepad)
Any help appreciated.