I've got a php page where I'm trying to get around the accessibility complaint that, "Embedded images should specify size attributes". Well, the images were being uploaded via ftp and their src attributes in html built from locations stored in a database, so I had complete unknowns from the point of view of the page.

Here's the solution, without any extra libs needed in php 4.1+, I believe.

if (!isNull(trim($myrow['studentHeadshotUrl']))) {
    $strImgLoc = $myrow['studentHeadshotUrl'];
    $imgProps = getimagesize($strImgLoc);
    $type = $imgProps['mime'];
    $width = $imgProps[0];
    $height = $imgProps[1];

    echo " \"Headshot        " src=\"" . $myrow['studentHeadshotUrl'] . "\"" .
        " height=" . $height .
        " width=" . $width .

And there was much rejoicing.

Labels: ,