Connecting Tech Pros Worldwide Forums | Help | Site Map

jpg header trouble

PaowZ
Guest
 
Posts: n/a
#1: Oct 2 '05
Hi there!

I'm trying to setup a function which could resize some jpgs 'on the
fly', I want them to be displayed into the browser.

Here is my function:

function Get_Redim_Jpg($file_jpg){
Header("Content-type: image/jpeg");
$src_im = ImageCreateFromJpeg($file_jpg);
$size = GetImageSize($image);
$src_w = $size[0];
$src_h = $size[1];
$dst_w = floor($src_w / 3);
$dst_h = floor($src_h / 3);
$dst_im = ImageCreateTrueColor($dst_w,$dst_h);

ImageCopyResampled($dst_im,$src_im,0,0,0,0,$dst_w, $dst_h,$src_w,$src_h);
ImageJpeg($dst_im);
ImageDestroy($dst_im);
imageDestroy($src_im);
}

and use it like that : '<img src="'.Get_Redim_Jpg("my_jpg").'">
So I must use header function to get it displayed as a jpg.
but I get the 'headers already sent' error..
I don't really see where I have to user header function to avoid
errors...

any idea ?

thanks a lot.
PaowZ


Philip Ronan
Guest
 
Posts: n/a
#2: Oct 2 '05

re: jpg header trouble


"PaowZ" wrote:
[color=blue]
> I'm trying to setup a function which could resize some jpgs 'on the
> fly', I want them to be displayed into the browser.
>
> Here is my function:
>
> function Get_Redim_Jpg($file_jpg){[/color]
(snip)[color=blue]
> }
>
> and use it like that : '<img src="'.Get_Redim_Jpg("my_jpg").'">
> So I must use header function to get it displayed as a jpg.
> but I get the 'headers already sent' error..[/color]

I suggest you start by learning a bit of HTML. The "src" attribute of an IMG
tag is supposed to contain a URL telling the browser where to find the image
resource. You seem to think that PHP allows you to stuff the contents of an
image file directly into the middle of your HTML source. I'm afraid it
doesn't.

--
phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/


PaowZ
Guest
 
Posts: n/a
#3: Oct 2 '05

re: jpg header trouble


u'r right...it doesn't...I have not been clear enough with
myself...anyway, using Get_Redim-Jpg "as is" won't prevent me from
header errors...

PaowZ

Philip Ronan
Guest
 
Posts: n/a
#4: Oct 2 '05

re: jpg header trouble


"PaowZ" wrote:
[color=blue]
> u'r right...it doesn't...I have not been clear enough with
> myself...anyway, using Get_Redim-Jpg "as is" won't prevent me from
> header errors...
>
> PaowZ[/color]

You still don't seem to understand the problem. Let me try to explain again.

(a) This is valid HTML:

<IMG src="resize-image.php?srcfile=x.jpg&w=80&h=40" alt="resized image"
width="80" height="40">

(b) This is invalid crap:

<IMG src="Content-Type: image/jpeg\x0D\x0A\x0D\x0A\xFF\xD8\xFF\xE0\x10JFIF
\x00\x01 ... etc. (raw JPEG data)

What you are currently attempting to produce is invalid crap. The "headers
already sent" error is occurring because PHP has already sent a
"Content-Type: text/html" header at the beginning of the HTML file. If you
want PHP to generate an image for this HTML file, then insert a URL pointing
to a script that generates the image, like in example (a).

--
phil [dot] ronan @ virgin [dot] net
http://vzone.virgin.net/phil.ronan/


R. Rajesh Jeba Anbiah
Guest
 
Posts: n/a
#5: Oct 2 '05

re: jpg header trouble


Philip Ronan wrote:[color=blue]
> "PaowZ" wrote:[/color]
<snip>[color=blue]
> (a) This is valid HTML:
>
> <IMG src="resize-image.php?srcfile=x.jpg&w=80&h=40" alt="resized image"
> width="80" height="40">
>
> (b) This is invalid crap:
>
> <IMG src="Content-Type: image/jpeg\x0D\x0A\x0D\x0A\xFF\xD8\xFF\xE0\x10JFIF
> \x00\x01 ... etc. (raw JPEG data)[/color]
<snip>

FWIW, data URL scheme may be used with IMG tag
<http://www.ietf.org/rfc/rfc2397> like:
<IMG src="data:image/gif;base64,fooo......." /> But, IE doesn't support
this.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

PaowZ
Guest
 
Posts: n/a
#6: Oct 2 '05

re: jpg header trouble


mmm...[color=blue][color=green]
>><IMG src="resize-image.php?srcfile=x.jpg&w=80&h=40" alt="resized image"
>>width="80" height="40">[/color][/color]

yes..this it what i did at first time, but now I realize why that
did'nt work....
I feel a bit ashamed, it was due to a path error in my
directories.....so...

I thank you, Phil.

PaowZ.

Closed Thread