Saturday, August 7, 2010

Quick fix for validating images

Quick fix for validating images on ready.mobi

"Specify the width and height of images in pixels as attributes of the IMG element. This allows devices to leave space for the images when they arrive, which means that pages don't have to be re-drawn several times"


PHP Code:
function img($file){
list(
$width$height) = getimagesize($file); $count strrpos ($file'http://');
if(
$count){ $n=1$alt  str_replace('http://',''$file); $alt explode('/',$alt); $alt  $alt[0]; $alt explode('.',$alt); $alt  $alt[0];
}
else{ 
$n=2$alt explode('/',$file); $alt  $alt[count($alt)-1]; $alt explode('.',$alt); $alt  $alt[0];
}
echo 
".$file."' width='".$width."' height='".$height."' alt ='".$alt."'/>";
?>
Example:
PHP Code:
img('tools/logo.gif');//my pictures img('http://waperos.net/tools/logo.gif');//external url ?>
Results:

HTML Code:
logo
logo 

No comments:

Post a Comment