Display image size in php

Display image size in php

  • PHP Tutorial
  • PHP | Introduction
  • PHP Full Form
  • How to set PHP development environment in windows ?
  • LAMP installation and important PHP configurations on Ubuntu
  • PHP | Coding Standards
  • PHP | Basic Syntax
  • PHP | Variables
  • PHP echo and print
  • PHP | Data Types
  • PHP | Strings
  • PHP | Constants
  • PHP | Magic Constants
  • PHP | Decision Making
  • PHP | Loops
  • PHP | Superglobals
  • PHP | Regular Expressions
  • PHP Examples
  • Describe PHP Include and Require
  • PHP | Basics of File Handling
  • PHP | fopen( ) (Function open file or URL)
  • PHP fread( ) Function
  • PHP fclose( ) Function
  • PHP | fwrite( ) Function
  • PHP | Uploading File
  • PHP Cookies
  • PHP | Sessions
  • PHP Filter and Filter Constant
  • Implementing callback in PHP
  • Exception Handling in PHP
  • PHP | Arrays
  • PHP array() Function
  • PHP | array_change_key_case() Function
  • PHP array_chunk() Function
  • PHP | array_column() Function
  • PHP array_combine() Function
  • PHP array_count_values() Function
  • PHP array_diff() function
  • PHP array_diff_assoc() Function
  • PHP array_diff_key() Function
  • PHP array_diff_uassoc() Function
  • PHP array_diff_ukey() Function
  • PHP array_fill() function
  • PHP array_fill_keys() Function
  • PHP Array Functions Complete Reference
  • PHP Date and Time
  • PHP | checkdate() Function
  • PHP | date_create(), date_format(), date_add() Functions
  • PHP | date_create_from_format() Function
  • PHP | date_date_set() Function
  • PHP | date_default_timezone_get() Function
  • PHP | date_default_timezone_set() Function
  • PHP | date_diff() Function
  • PHP | date_get_last_errors() Function
  • PHP | date_isodate_set() Function
  • PHP | date_modify() Function
  • PHP | date_offset_get() Function
  • PHP | date_parse_from_format() Function
  • PHP | date_parse() Function
  • PHP | date_sub() Function
  • PHP basename( ) Function
  • PHP chgrp( ) Function
  • PHP chmod( ) Function
  • PHP chown( ) Function
  • PHP copy( ) Function
  • PHP dirname( ) Function
  • PHP disk_free_space( ) Function
  • PHP disk_total_space( ) Function
  • PHP feof( ) Function
  • PHP fflush( ) Function
  • PHP | fgetc( ) Function
  • PHP | fgets( ) Function
  • PHP | fgetss( ) Function
  • PHP | file_exists( ) Function
  • PHP file_get_contents() Function
  • PHP Filesystem Functions Complete Reference
  • PHP | ftp_alloc() function
  • PHP | ftp_chdir() function
  • PHP | ftp_close() function
  • PHP | ftp_connect() function
  • PHP | ftp_delete() function
  • PHP | ftp_exec() function
  • PHP | ftp_get() function
  • PHP | ftp_put() function
  • PHP | ftp_get_option() function
  • PHP | ftp_login() function
  • PHP | ftp_mdtm() Function
  • PHP | ftp_mkdir() function
  • PHP | Ds\Map allocate() Function
  • PHP | Ds\Map apply() Function
  • PHP | Ds\Map capacity() Function
  • PHP | DS\Map clear() Function
  • PHP | Ds\Map __construct() Function
  • PHP Ds\Map copy() Function
  • PHP | Ds\Map count() Function
  • PHP | Ds\Map diff() Function
  • PHP | Ds\Map filter() Function
  • PHP | Ds\Map first() Function
  • PHP Ds\Map Functions Complete Reference
  • SplDoublyLinkedList in PHP
  • PHP SplDoublyLinkedList add() Function
  • PHP SplDoublyLinkedList bottom() Function
  • PHP SplDoublyLinkedList count() function
  • PHP SplFixedArray count() Function
  • PHP SplFixedArray current() Function
  • PHP SplFixedArray getSize() Function
  • PHP SplFixedArray key() Function
  • PHP SplObjectStorage addAll() Function
  • PHP SplObjectStorage attach() Function
  • PHP SplObjectStorage contains() Function
  • PHP SplObjectStorage count() Function
  • PHP SplQueue::__construct() Function
  • PHP SPL Data structures Complete Reference
  • PHP Tutorial
  • PHP | Introduction
  • PHP Full Form
  • How to set PHP development environment in windows ?
  • LAMP installation and important PHP configurations on Ubuntu
  • PHP | Coding Standards
  • PHP | Basic Syntax
  • PHP | Variables
  • PHP echo and print
  • PHP | Data Types
  • PHP | Strings
  • PHP | Constants
  • PHP | Magic Constants
  • PHP | Decision Making
  • PHP | Loops
  • PHP | Superglobals
  • PHP | Regular Expressions
  • PHP Examples
  • Describe PHP Include and Require
  • PHP | Basics of File Handling
  • PHP | fopen( ) (Function open file or URL)
  • PHP fread( ) Function
  • PHP fclose( ) Function
  • PHP | fwrite( ) Function
  • PHP | Uploading File
  • PHP Cookies
  • PHP | Sessions
  • PHP Filter and Filter Constant
  • Implementing callback in PHP
  • Exception Handling in PHP
  • PHP | Arrays
  • PHP array() Function
  • PHP | array_change_key_case() Function
  • PHP array_chunk() Function
  • PHP | array_column() Function
  • PHP array_combine() Function
  • PHP array_count_values() Function
  • PHP array_diff() function
  • PHP array_diff_assoc() Function
  • PHP array_diff_key() Function
  • PHP array_diff_uassoc() Function
  • PHP array_diff_ukey() Function
  • PHP array_fill() function
  • PHP array_fill_keys() Function
  • PHP Array Functions Complete Reference
  • PHP Date and Time
  • PHP | checkdate() Function
  • PHP | date_create(), date_format(), date_add() Functions
  • PHP | date_create_from_format() Function
  • PHP | date_date_set() Function
  • PHP | date_default_timezone_get() Function
  • PHP | date_default_timezone_set() Function
  • PHP | date_diff() Function
  • PHP | date_get_last_errors() Function
  • PHP | date_isodate_set() Function
  • PHP | date_modify() Function
  • PHP | date_offset_get() Function
  • PHP | date_parse_from_format() Function
  • PHP | date_parse() Function
  • PHP | date_sub() Function
  • PHP basename( ) Function
  • PHP chgrp( ) Function
  • PHP chmod( ) Function
  • PHP chown( ) Function
  • PHP copy( ) Function
  • PHP dirname( ) Function
  • PHP disk_free_space( ) Function
  • PHP disk_total_space( ) Function
  • PHP feof( ) Function
  • PHP fflush( ) Function
  • PHP | fgetc( ) Function
  • PHP | fgets( ) Function
  • PHP | fgetss( ) Function
  • PHP | file_exists( ) Function
  • PHP file_get_contents() Function
  • PHP Filesystem Functions Complete Reference
  • PHP | ftp_alloc() function
  • PHP | ftp_chdir() function
  • PHP | ftp_close() function
  • PHP | ftp_connect() function
  • PHP | ftp_delete() function
  • PHP | ftp_exec() function
  • PHP | ftp_get() function
  • PHP | ftp_put() function
  • PHP | ftp_get_option() function
  • PHP | ftp_login() function
  • PHP | ftp_mdtm() Function
  • PHP | ftp_mkdir() function
  • PHP | Ds\Map allocate() Function
  • PHP | Ds\Map apply() Function
  • PHP | Ds\Map capacity() Function
  • PHP | DS\Map clear() Function
  • PHP | Ds\Map __construct() Function
  • PHP Ds\Map copy() Function
  • PHP | Ds\Map count() Function
  • PHP | Ds\Map diff() Function
  • PHP | Ds\Map filter() Function
  • PHP | Ds\Map first() Function
  • PHP Ds\Map Functions Complete Reference
  • SplDoublyLinkedList in PHP
  • PHP SplDoublyLinkedList add() Function
  • PHP SplDoublyLinkedList bottom() Function
  • PHP SplDoublyLinkedList count() function
  • PHP SplFixedArray count() Function
  • PHP SplFixedArray current() Function
  • PHP SplFixedArray getSize() Function
  • PHP SplFixedArray key() Function
  • PHP SplObjectStorage addAll() Function
  • PHP SplObjectStorage attach() Function
  • PHP SplObjectStorage contains() Function
  • PHP SplObjectStorage count() Function
  • PHP SplQueue::__construct() Function
  • PHP SPL Data structures Complete Reference
Читайте также:  Enable exec function in php

Источник

Get the image size (height and width) in PHP

In this tutorial, I am going to tell you how to get the size of an image using PHP. The code snippets I am going to show you will retrieve the height and width of a given image file path.

There is a PHP function already available which will let you know the size of a given image file. The function is getimagesize() which will return an array that contains the height and width of an image file. It will also return some other properties, but here we will only take the image height and the width.

Suppose we want to get the size of an image image_file.jpg which is inside the directory image. Then we need to pass the file into the PHP getimagesize function just like below:

$imgsize_arr = getimagesize('image/image_file.jpg');

We have store the array data of coming from getimagesize function inside the variable $imgsize_arr.

If we want to see the size array data then we can see it by providing the code that you can see below:

echo "
"; print_r($imgsize_arr); echo "

";

The above code will return array data that looks like below:

Array ( [0] => 727 [1] => 640 [2] => 2 [3] => width="727" height="640" [bits] => 8 [channels] => 3 [mime] => image/jpeg )

In the array, you can see that the width of the image is available in the index 0 and the width in the index 1 of the array.

Now, let’s get the height and width from the array.

$img_width = $imgsize_arr[0]; $img_height = $imgsize_arr[1];

Complete and final code to simply display image width and height

Below is the PHP code which will display the image height and width on the screen:

As you can see that it is just a few lines of code which is easily retrieving the size of an image. It is simpler and easier than we can think. isn’t it?

Now you can use this method anywhere where you need to know the size of an image or you have to make your logic that is base on the size of the image.

Источник

Оцените статью