检索图像的分辨率并与其一起打印

Retrieving resolution of an image and print along with it

我有一个自定义 php 代码可以在 drupal 中打印图像列表。这是我为此功能编写的代码。

<?php
$dir = drupal_get_path('module', 'cproduct') . '/tdesignAPI/images  
 /Images';

$files1 = scandir($dir);

foreach ($files1 as $value) {
    if (strpos($value,'.png') !== false) {

    $p3 = drupal_get_path('module', 'cproduct') . '/tdesignAPI/images/Images/';?>

    <div class="sample_icons"><img src="<?php echo $p3 .$value;?>" width="100%" height="100%" /></div>
    <?php 
    }
    elseif(strpos($value,'.') === false) {
    //echo '<div class="sample_icons"><img src="tdesignAPI/images/folder.png" width="100%" height="100%" />' .$value. '</div>' ;
    }
        //echo "Value: $value<br />\n";
 }
 ?>

我的要求是检索所列图像的分辨率或尺寸,并与每张图像一起打印。我怎样才能做到这一点?

提前致谢

要检索图像的大小,请使用 getimagesize () 您可以阅读有关此方法的更多信息 here

使用getimagesize()函数。

尝试

foreach ($files1 as $value)
{
    if (strpos($value,'.png') !== false)
    {
        $image_resolution = getimagesize($dir.$value);
        $image_resolution = $image_resolution[3];

    $p3 = drupal_get_path('module', 'cproduct') . '/tdesignAPI/images/Images/';
    ?>
        <div class="sample_icons"><img src="<?php echo $p3 .$value;?>" <?php echo $image_resolution?> /></div>
    <?php 
    }
    elseif(strpos($value,'.') === false)
    {
    //echo '<div class="sample_icons"><img src="tdesignAPI/images/folder.png" width="100%" height="100%" />' .$value. '</div>' ;
    }
        //echo "Value: $value<br />\n";
}