I was wondering how can I find the width of an image using php.
Easy, you can use getimagesize:
list($width, $height) = getimagesize($filename);
getimagesize()
Use the GD libraries imagesx function, take a look at the manual page here.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With