473,320 Members | 1,922 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

jpg header trouble

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

Oct 2 '05 #1
5 3638
"PaowZ" wrote:
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){ (snip) }

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 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/
Oct 2 '05 #2
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

Oct 2 '05 #3
"PaowZ" wrote:
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


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/
Oct 2 '05 #4
Philip Ronan wrote:
"PaowZ" wrote: <snip> (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)

<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/

Oct 2 '05 #5
mmm...
<IMG src="resize-image.php?srcfile=x.jpg&w=80&h=40" alt="resized image"
width="80" height="40">


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.

Oct 2 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: trying_to_learn | last post by:
im in the primary stages of learning C++. The book im learning from says Dont use using namespace.. directive in header file However im trying to make the following header file.I need to include...
60
by: Derrick Coetzee | last post by:
It seems like, in every C source file I've ever seen, there has been a very definite include order, as follows: - include system headers - include application headers - include the header...
2
by: Fredrik Olsson | last post by:
I have dynamic library in a DLL. With a standard c header file to it. Writing a simple COM-wrapper in Visual Basic 6 was quite simple, and proves effective in providing my library's functionality...
6
by: G*rd*n | last post by:
I have been using the HTTP "Location" reponse header to direct a symbolic request to a CGI program to an actual URL/file. For example, let us suppose the CGI program's table indicates xyz ->...
9
by: Fei Liu | last post by:
In Accellerated C++, the author recommends that in a header file one should not declare using std::string, using std::vector etc instead one should directly specify the namespace specifier in...
3
by: fc2004 | last post by:
Hi, Is there any tools that could report where cyclic header dependency happens? this would be useful when working with a large project where tens or hundreds of headers files may form complex...
0
by: R. Tschirley | last post by:
Hi all, I've got some annoying trouble with IE's display of my new website header. On my site, the corporate logo shall be right-aligned: ...
10
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hello misters, I have an DAtalist that generates an html table with a header. There are many rows, and I want that it appears scroll horizontal and vertical, and the header be fixed. Any help...
2
by: =?Utf-8?B?QWxoYW1icmEgRWlkb3MgS2lxdWVuZXQ=?= | last post by:
Hello misters, In another post of the news, mister Manish Bafna, give me a reference: ...
5
by: Jeff | last post by:
I'm having some trouble wrapping my mind around header(), I'm used to just printing the header and leaving a blank line. Does php ignore whitespace before a header: <?php // no output here...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.