Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sprite Checker
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h1>Hello World</h1>
<?php
$data = array();
if ($handle = opendir('global/')) {
$counter = 0;
/* This is the correct way to loop over the directory. */
while (false !== ($entry = readdir($handle))) {
if( preg_match('/png/i',$entry) ){
list($width,$height) = getimagesize(__DIR__ . '/global/'. $entry);
$data[$entry]['height-1'] = $height;
$data[$entry]['width-1'] = $width;
$counter++;
}
}
closedir($handle);
}
if ($handle = opendir('global-2x/')) {
/* This is the correct way to loop over the directory. */
while (false !== ($entry = readdir($handle))) {
if( preg_match('/png/i',$entry) ){
list($width,$height) = getimagesize(__DIR__ . '/global-2x/'. $entry);
$data[$entry]['height-2'] = $height;
$data[$entry]['width-2'] = $width;
}
}
closedir($handle);
}
echo $counter;
?>
<table border="1">
<tr><td>Filename</td><td>Width (1x)</td><td>Height (1x)</td><td>Width (2x)</td><td>Height(2x)</td><td>Width Difference</td><td>Height Difference</td></tr>
<?php
foreach($data as $key=>$row):
$wdifference = round($row['width-1']) / round($row['width-2']) *100 . '%';
$hdifference = round($row['height-1']) / round($row['height-2']) *100 . '%';
?>
<tr>
<td><?=$key?></td>
<td><?=$row['width-1']?></td>
<td><?=$row['height-1']?></td>
<td><?=$row['width-2']?></td>
<td><?=$row['height-2']?></td>
<td><?=$wdifference?></td>
<td><?=$hdifference?></td>
</tr>
<?php endforeach; ?>
</table>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment