How can I find the width of an image using PHP?

前端 未结 7 1652
伪装坚强ぢ
伪装坚强ぢ 2020-12-10 15:40

I was wondering how can I find the width of an image using php.

相关标签:
7条回答
  • 2020-12-10 16:06

    As of PHP 7.1 you can do:

    [0 => $width, 1 => $height, 'mime' => $mime] = getimagesize($filename);
    

    This eliminates the need to turn $type into mime-type, while retaining the elegant array style list() assignments.

    0 讨论(0)
  • 2020-12-10 16:14

    You can try with this code, you can see more in www.php.net

    To a file:

    <?php
    list($width, $height, $type, $attr) = getimagesize("img/flag.jpg");
    echo "<img src=\"img/flag.jpg\" $attr alt=\"getimagesize() example\" />";
    ?>
    

    To URL:

    <?php
    $size = getimagesize("http://www.example.com/gifs/logo.gif");
    $size = getimagesize("http://www.example.com/gifs/lo%20go.gif");
    
    ?>
    

    Only you have to give an output to variable.

    0 讨论(0)
  • 2020-12-10 16:18

    Check here for official document

    list($Img_width, $Img_height) = getimagesize('Image Path');
    echo "Width: " . $Img_width. "<br />";
    echo "Height: " .  $Img_height;
    
    0 讨论(0)
  • 2020-12-10 16:19

    Use the GD libraries imagesx function, take a look at the manual page here.

    0 讨论(0)
  • 2020-12-10 16:21

    Easy, you can use getimagesize:

    list($width, $height) = getimagesize($filename);
    
    0 讨论(0)
  • 2020-12-10 16:22

    getimagesize()

    0 讨论(0)
提交回复
热议问题