Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

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

like image 469
fad Avatar asked Jul 18 '10 00:07

fad


4 Answers

Easy, you can use getimagesize:

list($width, $height) = getimagesize($filename);
like image 179
igorw Avatar answered Oct 02 '22 16:10

igorw


getimagesize()

like image 40
quantumSoup Avatar answered Oct 02 '22 16:10

quantumSoup


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

like image 30
Will A Avatar answered Oct 02 '22 15:10

Will A


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.

like image 30
Josh Ruiz Avatar answered Oct 02 '22 17:10

Josh Ruiz