获取图像名称、分辨率、路径、扩展名和fileszie


Get image name,resolution,path,extension and fileszie

我一直在工作,但无法获得任何解决方案。我有一个名为"下载"的文件夹,其中包含多个图像,我的任务是呼应所有图像并在其旁边显示相应的图像名称、路径分辨率、扩展名和文件大小。有人能帮忙吗?

我已经能够显示所有的图像。。

存储图像的路径是"C:''examplep''htdocs''2in1 file''download"

这是我的代码:

<?php
$files = glob("download/*.*");
echo"<table border=1>";
echo"<tr>";
echo"<td>";
echo"Preview";
echo"</td>";
echo"<td>";
echo"Name";
echo"</td>";
echo"<td>";
echo"Extension";
echo"</td>";
echo"<td>";
echo"Resolution";
echo"</td>";
echo"<td>";
echo"File Size";
echo"</td>";
echo"<td>";
echo"Path";
echo"</td>";
echo"</tr>";
for ($i=0; $i<count($files); $i++) {
$image = $files[$i];
echo"<tr>";
echo"<td>";
echo '<img src="'.$image .'" alt="Random image" width="100px" height="100px" />';
echo"</td>";

  }
 echo"</table>";
 ?>

我希望这将帮助

<?php
    $files = glob("download/*.*");
    echo"<table border=1>";
    for ($i = 0; $i < count($files); $i++) {
        $image = $files[$i];
        $path = pathinfo($image);
        $name = $path['filename'];
        $ext = $path['extension'];
        list($width, $height) = getimagesize($image);
        $resolution = $width . ' x ' . $height . ' Pexel';
        $path = $path['dirname'];
        $size = filesize($image);
        echo"<tr>";
        echo"<td>";
        echo '<img src="' . $image . '" alt="Random image" width="100px" height="100px" />';
        echo"</td>";
        echo"<td>";
        echo $name;
        echo"</td>";
        echo"<td>";
        echo $ext;
        echo"</td>";
        echo"<td>";
        echo $resolution;
        echo"</td>";
        echo"<td>";
        echo $size . ' Byte';
        echo"</td>";
        echo"<td>";
        echo $path;
        echo"</td>";
    }
    echo"</table>";
    ?>

您可以使用"getimagesize"表示分辨率,"filesize"表示图像大小,"realpath"表示绝对路径,"pathinfo"表示文件名、路径、扩展名等。

示例:

<?php
for ($i = 0; $i < count($files); $i++) {
    $image = $files[$i];
    $info = pathinfo($image);
    $resolution = getimagesize($image);
    echo "<tr>";
    echo "<td>";
    echo '<img src="'.$image .'" alt="Random image" width="100px" height="100px" />';
    echo "</td>";
    echo "<td>" . $info['filename'] . "</td>";
    echo "<td>" . $info['extension'] . "</td>";
    echo "<td>" . strval($resolution[0]) . "x" . strval($resolution[1]) . "</td>";
    echo "<td>" . strval(filesize($image)) . "</td>";
    echo "<td>" . realpath($image) . "</td>";
    echo "</tr>";
}
?>

getimagesize()--获取图像的大小

使用getimagesize()。或exif_read_data获取有关jpeg/tiff文件的更多信息。

使用pathinfo()获取有关扩展和路径的信息:

$info = pathinfo(__DIR__ . '/download/' . $image);
var_dump($info);
for ($i=0; $i<count($files); $i++) {
    $info = pathinfo($files[$i]);
    //only deal with images
    if(in_array(strtolower($info['extension']), array("jpg", "png", "gif", "svg"))){
        $image = $files[$i];
        list($width, $height, $type, $attr) = getimagesize($image);
        echo"<tr>";
        echo"<td>";
        echo '<img src="'.$image .'" alt="Random image" width="100px" height="100px" />';
        echo"</td>";
        echo "<td>".$info['filename']."</td>";
        echo "<td>".$info['extension']."</td>";
        echo "<td>$width x $height</td>";
        echo "<td>".filesize($image)." bytes</td>";
        echo "<td>$image</td>";
        echo"</tr>";
    }
}