Have you ever want to size a TABLE or DIV statement based upon the dimensions of an image? Using PHP this can be a relatively simple yet powerful task. Here's how...
// Define a variable to record the true source of the image(s) as found on the hosting server.
$source_image = $_SERVER['DOCUMENT_ROOT'] . '/images/';
// Append the source of the image to the image name. Define the image name prior to writing code
// or substitute with a real image name.
$filewpath = $source_image . $image;
// Calculate the width and height of the image and store in appropriately named variables.
list($width, $height) = getimagesize($filewpath);
// Define a style sheet based upon the width of the image.
$html_snippet.= '<style type="text/css">div.supporting-image {
float: left;
margin: 0 0 10px 10px;
padding: 0 0 0 0;
width: ' . $width . ';
} </style>';
// Define a variable to make note of all dynamically generated HTML code.
$html_snippet = '';
// Begin the <div> statement using the style sheet we defined earlier.
$html_snippet.= '<div class="supporting-image">';
// Place all of your HTML code here appending to the $html_snippet variable.
// Within your HTML content make sure you output the value of $html_snippet and close using </div>.





