include and imagejpg() weird behavior - maybe header?
| From: | Oli | Date: | Tue, 29 Jul 2003 17:34:06 +0000 |
| Subject: | include and imagejpg() weird behavior - maybe header? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-157358@lists.php.net to get a copy of this message | ||
I have a function that resizes images. If I put it in the same php file that
calles it it workes fine. Gives a nice thumbnail or whatever size I choose
to display. If I however put it in a seperate file and include it and call
it I get garbage and the following error:
Warning: Cannot modify header information - headers already sent by (output
started at /home/edal/public_html/album/image.php
Here is the resize function (in file image.php):
<?
function resize($filepath,$nw = 50,$string = '')
{
header("Content-type: image/jpeg");
$im = imagecreatefromjpeg($filepath);
$w = imagesx ($im);
$h = imagesy ($im);
$nh = round($h*$nw/$w,0);
$newim = imagecreatetruecolor($nw,$nh);
$black = imagecolorallocate($newim, 0, 0, 0);
imagecopyresampled($newim,$im,0,0,0,0,$nw,$nh,$w,$h);
imagestring($newim, 2, 5, 5, $string, $black);
imagedestroy($im);
return $newim;
} ?>
and the calling script:
<?php
include 'image.php';
$image = resize('Capri.jpg',200,'Capri');
imagejpeg($image);
imagedestroy($image);
?>
Any ideas?
Oli