Resize Window To Any Resolution

If you record videos of your desktop, especially the Terminal, it’s a challenge to get your window to fit properly in a 16:9 format. Without the proper tool, eyeballing a window to fit a certain resolution is a difficult task to do.

One of the tools I use to set my window to a resolution that I want is to use my browser as a guide. There are several websites out there that allow you to set your browser to any size or resolution. Head over to resizemybrowser.com.  They have several presets in varying resolutions.

If you don’t like any of their presets, then you can create your own. In addition, you can also manually adjust your current window to any size you want. The website gives you feedback of your resolution in real time. Once you set your browser to the right size, then you can match your Terminal with the size of your browser.

How To Force Downloads

Browsers behave differently when it comes to linking media files. Sometimes it will play them directly on the browser. Sometimes it will download them. Each browser seems to have their own rules. So, how do we force all browsers to download media files with just a click of a link.

A simple link like the one below simply won’t work.

<a href="video.mp4">Download</a>

One way of forcing downloads is to use a PHP function called readfile.

We have a file below called dl.php. We pass the filename to it, as well as set the path and URL.

$filename = $_GET['file'];
$filepath = "http://domain.com/download/";
$url = $filepath.$filename;
header("Content-disposition: attachment; filename=".$filename."");
header("Content-type: application/octet-stream");
readfile("".$url."");

Our HTML download link will look like this.

<a href="dl.php?file=video.mp4">Download</a>

It’s one way of forcing a download via the PHP route.

Detect Device, OS, Browser

If you like to deliver specific content to a certain device type, you can use PHP’s server environment settings to know what type of device, operating systems, and browser type is being used. The server environment setting we are interested in is ‘HTTP_USER_AGENT.’ This index contains a string that is given off by the user agent, the browser in this case. All devices pass down pieces of information identifying themselves, including the type of device, operating system, and browser that is being used.

If we were to look for an iPad for example, we need to perform the following commands:

$iPad   = stripos($_SERVER['HTTP_USER_AGENT'],"iPad");
if ($iPad) { 
  echo 'This is an iPad'; 
} else { 
  echo 'This is not'; 
}

Other Devices

$user_agent = $_SERVER['HTTP_USER_AGENT'];
 
$iPad   = stripos($user_agent,"iPad");
$iPod   = stripos($user_agent,"iPod");
$iPhone = stripos($user_agent,"iPhone");
$webOS  = stripos($user_agent,"webOS");
$BlackBerry = stripos($user_agent,"BlackBerry");
$RimTablet= stripos($user_agent,"RIM Tablet");
 
if (stripos($user_agent,"Android") && stripos($user_agent,"mobile")) { 
  $Android = true;
} elseif(stripos($user_agent,"Android")){
  $AndroidTablet = true;
}
 
if ($AndroidTablet) {
  echo 'This is an Android Tablet';
} else {
  echo 'This is not an Android Tablet';
}

Detect OS Type

$user_agent = $_SERVER['HTTP_USER_AGENT'];
 
if (preg_match('/linux/i', $user_agent)) { $platform = 'linux'; }
if (preg_match('/macintosh|mac os x/i', $user_agent)) { $platform = 'mac'; }
if (preg_match('/windows|win32/i', $user_agent)) { $platform = 'windows'; }
 
if ($platform == 'windows') {
  // do something
}

Detect Browser Type

$user_agent = $_SERVER['HTTP_USER_AGENT'];
 
if (preg_match('/MSIE/i',$user_agent)) { $browser = 'Internet Explorer'; }
if (preg_match('/Firefox/i',$user_agent)) { $browser = 'Mozilla Firefox'; }
if (preg_match('/Chrome/i',$user_agent)) { $browser = 'Google Chrome'; }
if (preg_match('/Safari/i',$user_agent)) { $browser = 'Apple Safari'; }
if (preg_match('/Opera/i',$user_agent)) { $browser = 'Opera'; }
if (preg_match('/Netscape/i',$user_agent)) { $browser = 'Netscape'; }
 
if ($browser == 'Google Chrome') {
  // do something
}

With the sample code above, you can pretty much single out any device and deliver specific content to it.