Pobierz wymiary obrazu [duplikat]

To pytanie ma już odpowiedź tutaj:

Mam url do obrazka, np. $var = http://example.com/image.png

Jak uzyskać jego wymiary do tablicy, Jak array([h]=> 200, [w]=>100) (height=200, width=100)?

Author: jooas, 2010-10-08

3 answers

Możesz użyć getimagesize funkcja taka:

list($width, $height) = getimagesize('path to image');
echo "width: " . $width . "<br />";
echo "height: " .  $height;
 101
Author: Sarfraz,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2013-03-13 17:04:43

Używając funkcji getimagesize możemy również uzyskać te właściwości danego obrazu -

<?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);
?>


wynik taki -

Width: 200
Wysokość: 100
Typ: 2
Atrybut: width = " 200 "height =" 100 "


Rodzaj obrazka -

1 = GIF
2 = JPG
3 = PNG
4 = SWF
5 = PSD
6 = BMP
7 = TIFF (intel byte order)
8 = TIFF (motorola byte order)
9 = JPC
10 = JP2
11 = JPX
12 = JB2
13 = SWC
14 = MFF
15 = WBMP
16 = XBM

 34
Author: Rohit Suthar,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-12-07 08:27:59
<?php 
    list($width, $height) = getimagesize("http://site.com/image.png"); 
    $arr = array('h' => $height, 'w' => $width );
?>
 14
Author: Dutchie432,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-10-08 12:47:27