getimagesize function and using variables to display an image

getimagesize function and using variables to display an image

am 12.11.2007 00:11:17 von Voodoo Jai

I have a dbn of images that I retrieve using SQL statements in
dreamweaver.
I want to get the file name using SQL and then place it into the
"getimagesize" function and then use this info (FileName, Width,
Height) to display the image on my web page.

something like this



//Assign 2 variables the Files name from the db and the file type

$type = 1;
$FileName = $row_TestDisplay['menu'];

list($width, $height, $type) = getimagesize($FileName);
?>






I can only get this to work using the height and width attributes in
the img tag, how can I do this.

Many thanks in advance

Voodoo Jai

Re: getimagesize function and using variables to display an image

am 12.11.2007 02:52:30 von darko

On Nov 12, 12:11 am, Voodoo Jai wrote:
> I have a dbn of images that I retrieve using SQL statements in
> dreamweaver.

What's "dbn"? Never mind. You have a db.

> I want to get the file name using SQL and then place it into the
> "getimagesize" function and then use this info (FileName, Width,
> Height) to display the image on my web page.
>

For terminology's sake - you don't place anything "into a function".
You call
a function with certain parameters.

> something like this
>
>
> >
> //Assign 2 variables the Files name from the db and the file type
>
> $type = 1;
> $FileName = $row_TestDisplay['menu'];
>
> list($width, $height, $type) = getimagesize($FileName);
> ?>
>


>
>
>

>

Why would you need "width='$width' height='$height'" at all, if $width
and $height
are image dimensions. You only do that when you need to display it
resized. Anyway,
it's a bad (and deprecated) practice to use HTML tags to define
element's style, e.g.
image size. Use CSS rules instead.

> I can only get this to work using the height and width attributes in
> the img tag, how can I do this.
>

So, ... what's the problem? I haven't seen any questions here. "I can
get
this to work... ...how can I do this." (with a full stop at the end of
interrogative).

Are you trying to resize the image from PHP, instead of defining its
dimensions in HTML?
Please try following the general rules of punctuation and being clear
about what you want
to be helped with.

> Many thanks in advance

You're welcome

>
> Voodoo Jai

Regards

Re: getimagesize function and using variables to display an image

am 14.11.2007 18:37:02 von Michael Fesser

..oO(Darko)

>On Nov 12, 12:11 am, Voodoo Jai wrote:
>>[...]
>> list($width, $height, $type) = getimagesize($FileName);
>> ?>
>>


>>
>>
>>

>>
>
>Why would you need "width='$width' height='$height'" at all, if $width
>and $height
>are image dimensions. You only do that when you need to display it
>resized.

There's another reason, given in the HTML spec:

| The height and width attributes give user agents an idea of the size
| of an image or object so that they may reserve space for it and
| continue rendering the document while waiting for the image data.

This prevents the surrounding content from jumping around when the image
appears.

>Anyway,
>it's a bad (and deprecated) practice to use HTML tags to define
>element's style, e.g.
>image size. Use CSS rules instead.

Correct, but IMHO this case is an exception. For images and some other
elements the 'width' and 'height' attributes are not deprecated for good
reasons.

Micha