tag or attribut for correct Image-size

Discussion in 'HTML' started by klausklausenator@googlemail.com, Sep 11, 2006.

  1. Guest

    Hi all,

    I have a php-generated webpage with images. My problem is: the Internet
    Explorer cannot calculate the correct image size. Because of this the
    images are not cached. So everytime a user clicks on some link all the
    images gets retransfered and the page loads very slow.
    You can check it if you right-click on an image and select properties.

    Is there a possibility to send the image and its actual
    size-information to the browser?

    I hope this is somehow clear.

    thanks in advance
    Klaus
    , Sep 11, 2006
    #1
    1. Advertising

  2. dorayme Guest

    In article
    <>,
    ""
    <> wrote:

    > Hi all,
    >
    > I have a php-generated webpage with images. My problem is: the Internet
    > Explorer cannot calculate the correct image size. Because of this the
    > images are not cached. So everytime a user clicks on some link all the
    > images gets retransfered and the page loads very slow.
    > You can check it if you right-click on an image and select properties.
    >
    > Is there a possibility to send the image and its actual
    > size-information to the browser?
    >
    > I hope this is somehow clear.


    If you are using PHP, then you should know above average stuff
    about HTML (PHP being something a bit more sophisticated server
    side control) like that in the mark up for images, the width and
    height attributes are quite important and are best specified
    exactly. It sounds like your PHP is not properly serving up the
    HTML. Browsers are not great image editors and it is best to tell
    the browser the exact width and height. In general.

    --
    dorayme
    dorayme, Sep 11, 2006
    #2
    1. Advertising

  3. <> scripsit:

    > I have a php-generated webpage with images.


    Do you have a URL for it?

    > My problem is: the
    > Internet Explorer cannot calculate the correct image size.


    Our problem is that we cannot see your real problem since you did not
    specify the URL and did not explain why you think that Internet Explorer
    cannot calculate the correct image size.

    > Because of this the images are not cached.


    And what makes you think so? I see little reason to expect image size to
    have anything to do with cacheing, which operates on "entities" referred to
    by URLs (btw, did I mention that you didn't mention the URL of your page?),
    _not_ to their specific content, still less rendering.

    > So everytime a user clicks on some
    > link all the images gets retransfered and the page loads very slow.


    Is there any reason to think that the images are "the same" as images that
    have already been fetched by the browser? Cacheing works by URLs and HTTP
    headers, not content. So if you have the same image accessible through
    different URLs*), they are not the same from the cacheing perspective. Image
    sizes have nothing to do with this.

    *) "URL" here means the resolved absolute URL, which may differ from the
    URLs in the src="..." attributes.

    > You can check it if you right-click on an image and select properties.


    I cannot, because you did not specify any URL and you did not say what is
    the "it" that I could check.

    > Is there a possibility to send the image and its actual
    > size-information to the browser?


    Yes, that's what servers do all the time.

    > I hope this is somehow clear.


    It isn't. It would be somewhat obscure even with a URL, but without a URL...

    --
    Jukka K. Korpela ("Yucca")
    http://www.cs.tut.fi/~jkorpela/
    Jukka K. Korpela, Sep 11, 2006
    #3
  4. Rik Guest

    wrote:
    > Hi all,
    >
    > I have a php-generated webpage with images. My problem is: the
    > Internet Explorer cannot calculate the correct image size. Because of
    > this the images are not cached. So everytime a user clicks on some
    > link all the images gets retransfered and the page loads very slow.
    > You can check it if you right-click on an image and select properties.


    I wouldn't know ether this is the problem.

    > Is there a possibility to send the image and its actual
    > size-information to the browser?


    ob_start();
    imagejpeg(); //(/...png()/...gif())
    header('Content-type: image/jpeg');
    header('Content-length: '.ob_get_length());
    ob_flush();

    Grtz,
    --
    Rik Wasmus
    Rik, Sep 11, 2006
    #4
  5. wrote:
    > Hi all,
    >
    > I have a php-generated webpage with images. My problem is: the Internet
    > Explorer cannot calculate the correct image size. Because of this the
    > images are not cached. So everytime a user clicks on some link all the
    > images gets retransfered and the page loads very slow.
    > You can check it if you right-click on an image and select properties.
    >
    > Is there a possibility to send the image and its actual
    > size-information to the browser?
    >
    > I hope this is somehow clear.
    >
    > thanks in advance
    > Klaus
    >


    You mean such as:

    <img src="/images/image1.gif" width=150 height="200" alt="My Image">

    Straight html - nothing to do with PHP.

    --
    ==================
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.

    ==================
    Jerry Stuckle, Sep 11, 2006
    #5
  6. Andy Dingley Guest

    dorayme wrote:
    > > My problem is: the Internet
    > > Explorer cannot calculate the correct image size.


    > > Is there a possibility to send the image and its actual
    > > size-information to the browser?


    > If you are using PHP, then you should know above average stuff
    > about HTML


    Not certain about this, but AFAIR the IE image non-caching problem is
    related to file size, not image size. It's _not_ a HTML problem and you
    can't solve it by using the <img width... height... > attributes. So
    it's a HTTP problem, not a HTML problem.

    _AFAIR_ (you should probably check this, as it's years since I hit
    this problem)
    IE doesn't cache things it doesn't know the storage size of. For images
    it finds this from a HTTP header which is sent before the image data.
    If your image is dynamically generated, then you won't know the size
    until it has been generated. If you code in the easy and obvious
    manner, you omit the header and just start writing image data back as
    fast as you create it. IE manages to display this, but it won't cache
    it.

    The fix is to generate it on the server as a PHP variable, find the
    size of it, write the size back in a HTTP header, then write the image
    data in the HTTP response.
    Andy Dingley, Sep 11, 2006
    #6
  7. Greg N. Guest

    Jukka K. Korpela wrote:

    >> I hope this is somehow clear.


    > It isn't. It would be somewhat obscure even with a URL, but without a
    > URL...


    You need to add WIDTH and HEIGHT attributes to your <IMG> tags. If you
    generate your html through PHP, you'll need to code something like this:

    $myimage="myfolder\mypic.jpg";
    $size = getimagesize($myimage);
    $width = $size[0];
    $height = $size[1];
    echo "<img src=$myimage width=$width height=$height>";

    I have not tested this code snippet, but you get the idea. It requires
    the function getimagesize() (which is not part of the PHP core, but
    pretty common these days) to be available on your server.

    --
    Gregor mit dem Motorrad auf Reisen:
    http://hothaus.de/greg-tour/
    Greg N., Sep 12, 2006
    #7
  8. Greg N. wrote:
    > Jukka K. Korpela wrote:
    >
    >
    >>> I hope this is somehow clear.
    >>>

    >
    >
    >> It isn't. It would be somewhat obscure even with a URL, but without a
    >> URL...
    >>

    >
    > You need to add WIDTH and HEIGHT attributes to your <IMG> tags. If you
    > generate your html through PHP, you'll need to code something like this:
    >
    > $myimage="myfolder\mypic.jpg";
    > $size = getimagesize($myimage);
    > $width = $size[0];
    > $height = $size[1];
    > echo "
    >
    >
    >

    There is also a nice shortcut:

    <img src=$myimage $size[3]>";


    getimagesize ... "Returns an array with 4 elements ...
    .... Index 3 is a text string with the correct height="yyy" width="xxx"
    string that can be used directly in an IMG tag."

    --
    *****************************
    Chuck Anderson • Boulder, CO
    http://www.CycleTourist.com
    *****************************
    Chuck Anderson, Sep 12, 2006
    #8
  9. Greg N. <> scripsit:

    > Jukka K. Korpela wrote:
    >
    >>> I hope this is somehow clear.

    >
    >> It isn't. It would be somewhat obscure even with a URL, but without a
    >> URL...

    >
    > You need to add WIDTH and HEIGHT attributes to your <IMG> tags.


    No I don't. You seem to have no idea of I what I wrote in my message, and
    you quoted something that you don't comment on.

    And your message has nothing to do with the problem posed, though it seems
    to involve a misconception that the original poster also had.

    --
    Jukka K. Korpela ("Yucca")
    http://www.cs.tut.fi/~jkorpela/
    Jukka K. Korpela, Sep 12, 2006
    #9
  10. Guest

    Thanks everyone for trying to answer my question.

    The solution (for me) lies not in using the height and width attribute
    in the <src>-Tag, because my problem had to do something with the file
    size and not with the image size. Sorry for the confusion.

    The solution was to send an special header before the actual picture.
    So now I use something like this:

    <?php
    ob_start();
    header("Expires: " . date("D, j M Y H:i:s", time() + (86400 * 7)) . "
    UTC");
    header("Cache-Control: Public");
    header("Pragma: Public");
    $im = imagecreatefromgif($src);
    imagegif($im);
    header('Content-type: image/gif');
    header('Content-length: ' . ob_get_length());
    ob_flush();
    ?>

    And it was an IE caching problem. Now it works pretty well. Special
    thanks goes to Andy Dingley and Rik.

    Klaus
    , Sep 16, 2006
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. shruds
    Replies:
    1
    Views:
    757
    John C. Bollinger
    Jan 27, 2006
  2. khaled Hajjar
    Replies:
    5
    Views:
    403
    Patrick TJ McPhee
    Oct 19, 2003
  3. hp_

    variable and attribut

    hp_, Sep 13, 2004, in forum: XML
    Replies:
    3
    Views:
    413
  4. pcouas

    JOX and attribut problem

    pcouas, Jan 22, 2007, in forum: Java
    Replies:
    4
    Views:
    1,118
    pcouas
    Jan 23, 2007
  5. Tony Johansson

    reference attribut

    Tony Johansson, Aug 12, 2005, in forum: C++
    Replies:
    4
    Views:
    343
    Adrian
    Aug 12, 2005
Loading...

Share This Page