Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get Image Height and Width as integer values?

Tags:

php

I've tried to use the PHP function getimagesize, but I was unable to extract the image width and height as an integer value.

How can I achieve this?

like image 368
Mostafa Elkady Avatar asked Feb 01 '10 18:02

Mostafa Elkady


People also ask

How do you get the image width and height using JS?

Answer: Use the JavaScript clientWidth property You can simply use the JavaScript clientWidth property to get the current width and height of an image. This property will round the value to an integer.

How can get width and height of image in PHP?

The getimagesize() function in PHP is an inbuilt function which is used to get the size of an image. This function accepts the filename as a parameter and determines the image size and returns the dimensions with the file type and height/width of image.

How can get image width and height in jQuery?

width(); alert(imageWidth); var imageHeight = Imgsize. height();


2 Answers

Try like this:

list($width, $height) = getimagesize('path_to_image'); 

Make sure that:

  1. You specify the correct image path there
  2. The image has read access
  3. Chmod image dir to 755

Also try to prefix path with $_SERVER["DOCUMENT_ROOT"], this helps sometimes when you are not able to read files.

like image 190
Sarfraz Avatar answered Sep 20 '22 20:09

Sarfraz


list($width, $height) = getimagesize($filename) 

Or,

$data = getimagesize($filename); $width = $data[0]; $height = $data[1]; 
like image 34
davethegr8 Avatar answered Sep 16 '22 20:09

davethegr8