Get Image Information

Written by @m_k_amin 21 November 2012

If you have images on your site and want to find their characteristics such as Height, Width and etc., this script helps you by preparing a function that needs just the image file path! Enjoy.

Code Snippet:

                                                
                                                <!-- this script is provided by https://www.phpfreecode.com coded by: Kerixa Inc. -->
<!-- This Script is from www.phpfreecpde.com, Coded by: Kerixa Inc-->
<?php
$img='1.jpg';
print_r(image_get_info($img));
function image_get_info($file) {
  // Proceed no further if this file doesn't exist. Some web servers (IIS) may
  // not pass is_file() for newly uploaded files, so we need two checks here.
  if (!is_file($file) && !is_uploaded_file($file)) {
    return FALSE;
  }

  $details = FALSE;
  $data = @getimagesize($file);
  $file_size = @filesize($file);

  if (isset($data) && is_array($data)) {
    $extensions = array(
      '1' => 'gif',
      '2' => 'jpg',
      '3' => 'png',
    );
    $extension = array_key_exists($data[2], $extensions) ?  $extensions[$data[2]] : '';
    $details = array(
      'width' => $data[0], 
      'height' => $data[1], 
      'extension' => $extension, 
      'file_size' => $file_size, 
      'mime_type' => $data['mime'],
    );
  }

  return $details;
}
?>
<br><br><font face="Tahoma"><a target="_blank" href="http://www.phpfreecode.com/"><span style="font-size: 8pt; text-decoration: none">PHP Free Code</span></a></font><a target='_blank' href='https://www.phpfreecode.com' style='font-size: 8pt; text-decoration: none'>Php Best Codes</a>                                                
                                            

Example:


About @m_k_amin

This user is pending a biography.

M

Comments


Here you can leave us commments. Let us know what you think about this code tutorial!

0 / 300

TRENDING POST
1
2
3
4
5
VISITORS
Online Users: 12
Recent Members: grkkid, Manaakividuinfo.com, karticksv, sava, tinatina
advertisement 2