qasabah
12-11-2006, 09:29 PM
I have a php script that calls an image and various other items but I decided I wanted to specify the image size rather than have it look for it and apply it itself.
Problem is I don't know anything about php so my effort probably resembles what a monkey flailing around with a typewriter might produce.
Any help would be greatly appreciated.
function showImage( $ini=null ) {
global $IMG_CONFIG_FILE;
# if no custom ini file has been specified, use the default
$ini_file = $ini ? $ini : $IMG_CONFIG_FILE;
# read the config file into an array or die trying
$images = @parse_ini_file($ini_file,true);
if (! $images) {
die('Unable to read ini file.');
}
# pick a random image from the parsed config file
$img = array_rand($images);
# get the selected image's css id if one exists
$id = $images[$img]['id'] ?
sprintf( ' id="%s" ', $images[$img]['id'] ) :
'';
# get the selected image's css class if one exists
$class = $images[$img]['class'] ?
sprintf( ' class="%s" ', $images[$img]['class'] ) :
'';
# get selected image's dimensions
$width = $images[$img]['width'] ?
sprintf( ' width="%s" ',$images[$img]['width'] ) :
";
# get selected image's dimensions
$height = $images[$img]['height'] ?
sprintf( ' height="%s" ',$images[$img]['height'] ) :
";
# if an url was specified, output the opening A HREF tag
if ( $images[$img]['url'] ) {
printf(
'<a href="%s" title="%s">',
$images[$img]['url'],
$images[$img]['title']
);
}
# output the IMG tag
printf(
'<img src="%s" alt="%s" width="%s" height="%s" %s %s%s/>',
$images[$img]['src'],
$images[$img]['alt'],
$id,
$class
$images[$img]['width'],
$images[$img]['height'],
);
# if an url was specified, output the closing A HREF tag
if ( $images[$img]['url'] ) {
echo('</a>');
}
}
?>
[plus44]
src = music/music_images/plus44.jpg
alt = Plus 44- When your Heart Stops Beating
url = music/heartstops.html
title = Plus 44- When Your Heart Stops Beating
width = 150
height = 136
Problem is I don't know anything about php so my effort probably resembles what a monkey flailing around with a typewriter might produce.
Any help would be greatly appreciated.
function showImage( $ini=null ) {
global $IMG_CONFIG_FILE;
# if no custom ini file has been specified, use the default
$ini_file = $ini ? $ini : $IMG_CONFIG_FILE;
# read the config file into an array or die trying
$images = @parse_ini_file($ini_file,true);
if (! $images) {
die('Unable to read ini file.');
}
# pick a random image from the parsed config file
$img = array_rand($images);
# get the selected image's css id if one exists
$id = $images[$img]['id'] ?
sprintf( ' id="%s" ', $images[$img]['id'] ) :
'';
# get the selected image's css class if one exists
$class = $images[$img]['class'] ?
sprintf( ' class="%s" ', $images[$img]['class'] ) :
'';
# get selected image's dimensions
$width = $images[$img]['width'] ?
sprintf( ' width="%s" ',$images[$img]['width'] ) :
";
# get selected image's dimensions
$height = $images[$img]['height'] ?
sprintf( ' height="%s" ',$images[$img]['height'] ) :
";
# if an url was specified, output the opening A HREF tag
if ( $images[$img]['url'] ) {
printf(
'<a href="%s" title="%s">',
$images[$img]['url'],
$images[$img]['title']
);
}
# output the IMG tag
printf(
'<img src="%s" alt="%s" width="%s" height="%s" %s %s%s/>',
$images[$img]['src'],
$images[$img]['alt'],
$id,
$class
$images[$img]['width'],
$images[$img]['height'],
);
# if an url was specified, output the closing A HREF tag
if ( $images[$img]['url'] ) {
echo('</a>');
}
}
?>
[plus44]
src = music/music_images/plus44.jpg
alt = Plus 44- When your Heart Stops Beating
url = music/heartstops.html
title = Plus 44- When Your Heart Stops Beating
width = 150
height = 136