|
|
|
| Сабж.. а то у меня все картинки размещаются горизонтально и сильно растягивают страницу (ну я думаю понятно какие это создёт неудобства) | |
|
|
|
|
|
|
|
для: DEM
(04.03.2007 в 13:48)
| | а в строчку - это не горизонтально?
выход - вложенные таблицы | |
|
|
|
|
|
|
|
для: elenaki
(04.03.2007 в 16:01)
| | Я просто все данные беру из таблицы и перебираю с помощью WHILE() и если брать в таблицу, то... хм... странно будет.. хотя можно использовать не WHILE, a FOR и просто например писать
if($i крато 5)
{
echo "<table>";
}
Но мне кажется это будет странно | |
|
|
|
|
|
|
|
для: DEM
(04.03.2007 в 18:27)
| | непонятна сама постановка вопроса
1. у вас много картинок?
2. надо выводить их в таблице по 5 в строку?
3. картинки одинакового размера или их надо ресайзить?
посмотрите этот скрипт, он читает данную директорию, выбирает картинки, изменяет им размеры до заданных (пропорционально) и выводит в таблицу с заданным количеством столбцов:
<?
// Some configuration variables !
$maxWidth = 90;
$maxHeight = 90;
$maxCols = 3;
$webDir = "http://localhost/PHP/image_resize/";
$localDir = "/home/sites/www/public_html/image_resize/";
// build the www path:
$me = $_SERVER['PHP_SELF'];
$Apathweb = explode("/", $me);
$myFileName = array_pop($Apathweb);
$pathweb = implode("/", $Apathweb);
$myURL = "http://".$_SERVER['HTTP_HOST'].$pathweb."/".$myFileName;
$PAGE_BASE['www'] = $myURL;
// build the file path:
strstr( PHP_OS, "WIN") ? $strPathSeparator = "\\" : $strPathSeparator = "/";
$pathfile = getcwd ();
$PAGE_BASE['physical'] = $pathfile.$strPathSeparator.$myFileName;
// this is so you can verify the results:
$www = $PAGE_BASE['www'];
$physical = $PAGE_BASE['physical'];
//echo "$physical<p>";
//echo "$www<p>";
$AutorisedImageType = array ("jpg", "jpeg", "gif", "png");
?>
<table align="center" border='1' cellspacing='5' cellpadding='5' style="border-collapse:collapse; border-style: dotted">
<tr>
<?
// Open localDir
$dh = opendir($localDir);
while (false !== ($filename = readdir($dh))) {
$filesArray[] = $filename;
}
// Display and resize
foreach ($filesArray as $images) {
$ext = substr($images, strpos($images, ".")+1, strlen($images));
if( in_array($ext, $AutorisedImageType) ) {
list($width, $height, $type, $attr) = @getimagesize( $localDir.$images );
$xRatio = $maxWidth / $width;
$yRatio = $maxHeight / $height;
if ( ($width <= $maxWidth) && ($height <= $maxHeight) ) {
$newWidth = $width;
$newHeight = $height;
}
else if (($xRatio * $height) < $maxHeight) {
$newHeight = ceil($xRatio * $height);
$newWidth = $maxWidth;
}
else {
$newWidth = ceil($yRatio * $width);
$newHeight = $maxHeight;
}
if($i == $maxCols) {
echo "</tr><tr>";
$i = 0;
}
echo "<td align='center' valign='middle' width='$maxWidth' height='$maxHeight'><img src='".$webDir.$images."' width='$newWidth' height='$newHeight'></td>";
$i++;
}
}
?>
</tr>
</table>
|
| |
|
|
|