I was wondering how can I find the width of an image using php.
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.
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.
Check here for official document
list($Img_width, $Img_height) = getimagesize('Image Path');
echo "Width: " . $Img_width. "<br />";
echo "Height: " . $Img_height;
Use the GD libraries imagesx function, take a look at the manual page here.
Easy, you can use getimagesize:
list($width, $height) = getimagesize($filename);
getimagesize()