Skip to content

Instantly share code, notes, and snippets.

@mephraums
Created April 21, 2014 23:52

Revisions

  1. mephraums created this gist Apr 21, 2014.
    85 changes: 85 additions & 0 deletions gistfile1.phtml
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,85 @@
    <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>