Using PHP with getID3() to find out if a video is landscape or portrait

In this post I am going to show you how to use PHP with the getID3() engine to find out if a video is landscape or portrait.

First things first, you will need to have the getID3() library of files. You can download them here: https://github.com/JamesHeinrich/getID3/archive/master.zip and unzip them to your project. After you have unzipped the folder, navigate to the demos folder and create a new PHP file in there. You can test the demo below in this new PHP file.

The first line of code you will need to include is the getID3() library:

require_once('../getid3/getid3.php');

Now point to the video file you would like to analyze and create a new instance.

$filename = 'some_video.mp4'; 

$getID3 = new getID3;

Now run the analyze method to get the width and height of the video.

$file = $getID3->analyze($filename);

The file variable now contains an array of information about the video file including the width and height shown below.

$width = $file['video']['resolution_x'];
$height = $file['video']['resolution_y']; 

Now you can find out if the video is landscape or portrait.

if($width > $height) { 

    echo 'Is landscape';

}else {

    echo 'Is portrait';

This is all you need to find out if the video is landscape or portrait. getID3() is released under multiple licenses. As always, please be sure to check the readme file before use in your projects to adhere to the licenses.

Comments

Popular posts from this blog

Build 6 is here

An example of chaining jQuery Ajax request callbacks

Creating hashtag hyperlinks on the fly for your website