【问题标题】:Get image dimensions [duplicate]获取图像尺寸[重复]
【发布时间】:2011-04-22 21:05:56
【问题描述】:

我有一个图片的网址,例如$var = http://example.com/image.png

如何将它的维度转换为数组喜欢 array([h]=> 200, [w]=>100)(height=200, width=100)

【问题讨论】:

    标签: php image dimensions


    【解决方案1】:

    您可以像这样使用getimagesize 函数:

    list($width, $height) = getimagesize('path to image');
    echo "width: " . $width . "<br />";
    echo "height: " .  $height;
    

    【讨论】:

    • OP 确实问过“我如何将它的维度放入一个数组”,所以我不确定为什么这是完全接受的答案......不过 GJ。
    • @Dutchie432:他的主要意思是一旦你有宽度和高度,如何获取图像尺寸和创建一个数组是/应该很容易:)
    • 我认为可以肯定地说这是您的(可能是正确的)假设,而不是针对问题的具体情况。
    • 此选项不支持 https:// 协议。有人知道安全图像大小检测的任何好选择吗?
    • @JustinKaz 支持https,但是你的服务器需要有openSSL。例如,stackoverflow.com/a/8518616/76672 https 对我来说效果很好。
    【解决方案2】:
    <?php 
        list($width, $height) = getimagesize("http://site.com/image.png"); 
        $arr = array('h' => $height, 'w' => $width );
    ?>
    

    【讨论】:

      【解决方案3】:

      使用 getimagesize 函数,我们还可以获取该特定图像的这些属性-

      <?php
      
      list($width, $height, $type, $attr) = getimagesize("image_name.jpg");
      
      echo "Width: " .$width. "<br />";
      echo "Height: " .$height. "<br />";
      echo "Type: " .$type. "<br />";
      echo "Attribute: " .$attr. "<br />";
      
      //Using array
      $arr = array('h' => $height, 'w' => $width, 't' => $type, 'a' => $attr);
      ?>
      


      这样的结果 -

      宽度:200
      身高:100
      类型:2
      属性:width='200' height='100'


      图片类型考虑喜欢 -

      1 = GIF
      2 = JPG
      3 = PNG
      4 = SWF
      5 = PSD
      6 = BMP
      7 = TIFF(英特尔字节顺序)
      8 = TIFF(摩托罗拉字节顺序)
      9 = JPC
      10 = JP2
      11 = JP
      12 = JB2
      13 = SWC
      14 = IFF
      15 = WBMP
      16 = XBM

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-08-03
        • 1970-01-01
        • 2017-04-06
        • 1970-01-01
        • 2011-08-02
        • 2011-07-07
        • 2012-07-09
        • 2015-03-27
        相关资源
        最近更新 更多