tag or attribut for correct Image-size

K

klausklausenator

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
 
D

dorayme

"(e-mail address removed)"
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.
 
J

Jukka K. Korpela

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...
 
R

Rik

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,
 
J

Jerry Stuckle

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.
(e-mail address removed)
==================
 
A

Andy Dingley

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.
 
G

Greg N.

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.
 
C

Chuck Anderson

Greg said:
Jukka K. Korpela wrote:

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."
 
J

Jukka K. Korpela

Greg N. said:
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.
 
K

klausklausenator

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top