【问题标题】:PHP Give an image width and heightPHP 给出图像的宽度和高度
【发布时间】:2012-12-23 22:31:22
【问题描述】:

如何设置尺寸,我想以 400X400 格式显示边缘图像:

  • 高度 = 400
  • 宽度 = 400

请给出 400X400 的代码大小,谢谢。

代码如下:

<?php   
    // Grab the data from our people table
    $sql = "select * from njerz";
    $result = mysql_query($sql) or die ("Could not access DB: " . mysql_error());

    while ($row = mysql_fetch_assoc($result))   {
        echo "<div class=\"picture\">";
        echo "<p>";

        // Note that we are building our src string using the filename from the database
        echo $row['fname'] . " " . $row['lname'] . "<br />";
        echo "<img src=\"images/" . $row['filename'] . "\" alt=\"\" /><br ;
        echo "</p>";
        echo "</div>";
    }
?>

【问题讨论】:

    标签: php html image echo image-size


    【解决方案1】:

    不知道我理解的对不对:

    echo "<img src=\"images/" . $row['filename'] . "\" alt=\"\" height=\"400\" width=\"400\" /><br />";
    

    如果您想设置尺寸,这就是您所需要的一切

    【讨论】:

    • height=\"400\" width=\"400\" /&gt; 认真的吗?我们怎么知道它是否以像素为单位?你不应该包括px
    • 高度和宽度属性不要指望 px 最后。他们从来没有。他们期望一个整数,表示像素或百分比。然而,它们是贬值的。高度和宽度 CSS 属性确实需要 px 或 %。
    【解决方案2】:

    你只需要添加一个样式属性style="width:400px; height:400px;"

    echo '<img src="images/'. $row['filename'] .'" style="width:400px; height:400px;" alt="" /><br />';
    

    【讨论】:

      【解决方案3】:

      请检查我的代码

      list($width, $height, $type, $attr) = getimagesize("PATH_OF_THE_IMAGE/".$row['filename']);
      
      echo "<img src=\"images/" . $row['filename'] . "\" alt=\"\" height=\"".$height."\" width=\"".$width."\" /><br />";
      

      【讨论】:

        猜你喜欢
        • 2011-11-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-10-28
        • 1970-01-01
        • 2019-01-28
        • 2018-07-05
        相关资源
        最近更新 更多