jpg header trouble

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • PaowZ

    #1

    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 = ImageCreateFrom Jpeg($file_jpg) ;
    $size = GetImageSize($i mage);
    $src_w = $size[0];
    $src_h = $size[1];
    $dst_w = floor($src_w / 3);
    $dst_h = floor($src_h / 3);
    $dst_im = ImageCreateTrue Color($dst_w,$d st_h);

    ImageCopyResamp led($dst_im,$sr c_im,0,0,0,0,$d st_w,$dst_h,$sr c_w,$src_h);
    ImageJpeg($dst_ im);
    ImageDestroy($d st_im);
    imageDestroy($s rc_im);
    }

    and use it like that : '<img src="'.Get_Redi m_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

    #2
    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_Redi m_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



    Comment

    • PaowZ

      #3
      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

      Comment

      • Philip Ronan

        #4
        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?srcfi le=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\x0 D\x0A\xFF\xD8\x FF\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



        Comment

        • R. Rajesh Jeba Anbiah

          #5
          |OT| IMG and data URL scheme (Was 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?srcfi le=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\x0 D\x0A\xFF\xD8\x FF\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/

          Comment

          • PaowZ

            #6
            Re: jpg header trouble

            mmm...[color=blue][color=green]
            >><IMG src="resize-image.php?srcfi le=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.

            Comment

            Working...