note 42662 added to function.getimagesize
| From: | diablx at hotmail dot com | Date: | Tue, 25 May 2004 18:36:30 +0000 |
| Subject: | note 42662 added to function.getimagesize | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-70075@lists.php.net to get a copy of this message | ||
I'm sorry for they other scripts, but I made one mistake about the image resizing... here is a
working script !
<?
// Some configuration variables !
$maxWidth = 90;
$maxHeight = 90;
$maxCols = 8;
$webDir = "https://localhost/images/";
$localDir = $_SERVER['DOCUMENT_ROOT']."/images/";
$AutorisedImageType = array ("jpg", "jpeg", "gif", "png");
?>
<center>
<table 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>
</center>
----
Manual Page -- http://www.php.net/manual/en/function.getimagesize.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42662
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42662&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42662&report=yes
Search -- http://master.php.net/manage/user-notes.php