Image GD, PHP and wordpress
-
Ive written some code that pulls up an image, or creates it if its not about….
It works fine (https://syntheticcheese.co.uk/wordpress/wp-content/themes/sc-1/index2.php) on its own, but when i try and pull it into wordpress by using:
<?php synhead(text,comment) ; ?>
in either the writing box (with a php plugin) or directly into one of the files it fails completely.
Warning: Cannot modify header information - headers already sent by (output started at /home/cheese/public_html/wordpress/wp-content/themes/sc-1/header.php:7) in /home/cheese/public_html/wordpress/wp-content/themes/sc-1/functions.php on line 13
Warning: imagecreatefrompng(headerexample.png): failed to open stream: No such file or directory in /home/cheese/public_html/wordpress/wp-content/themes/sc-1/functions.php on line 16
Warning: imagecolorallocate(): supplied argument is not a valid Image resource in /home/cheese/public_html/wordpress/wp-content/themes/sc-1/functions.php on line 19
Warning: imagecolorallocate(): supplied argument is not a valid Image resource in /home/cheese/public_html/wordpress/wp-content/themes/sc-1/functions.php on line 20
Warning: imagettftext() expects parameter 1 to be resource, boolean given in /home/cheese/public_html/wordpress/wp-content/themes/sc-1/functions.php on line 27
Warning: imagettftext() expects parameter 1 to be resource, boolean given in /home/cheese/public_html/wordpress/wp-content/themes/sc-1/functions.php on line 28
Warning: imagepng(): supplied argument is not a valid Image resource in /home/cheese/public_html/wordpress/wp-content/themes/sc-1/functions.php on line 31
Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/cheese/public_html/wordpress/wp-content/themes/sc-1/functions.php on line 32
I’ve checked all the files, they are in place, and all 777.
here is the code:
<?php
function synhead($text,$comment){
$filename = 'images/headers/header_'.$text.'_'.$comment.'.png';if (file_exists($filename)) // is the file made?
{
echo $filename ;
}
else
{
// if not, lets make it for next time.
// Set the content-type
header('Content-type: image/png');// Create the image, base it on the demo.
$im = imagecreatefrompng('headerexample.png');// colors
$blue= imagecolorallocate($im,200,215,225);
$darkblue = imagecolorallocate($im,-88,-102,-114); // the - turns of anti alising. Which is nice.// fonts
$font_text = 'tahomabd.ttf'; // no auto bold :o
$comment_text = 'tahoma.ttf';// text
imagettftext($im, 12, 0, 25, 21, $blue, $font_text, $text);
imagettftext($im, 7, 0, 51, 31, $darkblue, $comment_text, $comment);imagepng($im,$filename); //save the image
imagedestroy($im); // drops if from the ram
}
}
?>oh, and i included the function file into the header with
<?php include_once(dirname(__FILE__) . '/
functions.php'); ?>Thanks for any help.
Also, is it possible to make a button for the editor that will include this function and allow me to change the arguments depending on the pic i want?
- The topic ‘Image GD, PHP and wordpress’ is closed to new replies.