Skip to content

Instantly share code, notes, and snippets.

@jan-martinek
Last active August 9, 2017 11:43
Show Gist options
  • Save jan-martinek/428c6cc285dc98ae57fbb0a5216338f8 to your computer and use it in GitHub Desktop.
Save jan-martinek/428c6cc285dc98ae57fbb0a5216338f8 to your computer and use it in GitHub Desktop.
Preview last screenshot on another device
<?php
/* I use this to quickly preview last taken screenshot on my retina ipad.
* (I use xip.io to quickly access virtual hosts on my dev machine.)
*
* Be sure to allow write in the dir where this script is located.
*
* It's possible to change the directory where screenshots are stored on mac.
* Consider using one exclusively for this purpose
* (see google.com/search?q=change+screenshot+location+mac).
*/
$pixelRatio = 2; // to preview pics on @2x retina screen
$dir = '/Users/username/Documents/Screenshots'; // allow server to read this dir
// find file
$files = glob($dir . "/*.png");
$files = array_combine($files, array_map("filemtime", $files));
arsort($files);
$latest = key($files);
copy($latest, 'img.png');
// set img size
$size = getimagesize($latest);
$width = $size[0] / $pixelRatio;
$height = $size[1] / $pixelRatio;
echo "<img src=\"img.png\" width=\"$width\" height=\"$height\">";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment