Just wondering if there was someone out there that could offer help in optimizing my script which "derpifies" images.
<?php
/**
* If you don't understand what this does
* you have no hope as a programmer.
*
*/
function usage ( )
{
// Ahhh the marvels of echo, such a wonderful tool
// yet so advanced that a beginner will tremble at the
// word. Woe's me is spoken to the RAM with such care.
echo "\n";
echo "----------------------------\n";
echo "> Derp.PHP is a CLI based \n";
echo "> image derpification tool. \n";
echo "> Use only with: \n";
echo "> jpeg, gif, or png files \n";
echo "> \n";
echo "> Usage: \n";
echo "> derp.php path/to/file \n";
echo "----------------------------\n";
echo "\n";
}
/**
* In this function we make sure the end user isn't
* a total moran by checking weather we have access
* to certain hacker libraries.
*
**/
function make_checks ( )
{
# A beautiful built_in function that is necessary to
# this programs inherited existence, such a lovely sight.
if ( !function_exists('imagecopy') )
{
// Here we throw an error if we encounter a stupid user.
// >2012
// >Not having GD installed.
//
// ISHYGDDT.
echo "\n";
echo ">>> ERROR <<<\n";
echo ">>> INSTALL THE GD LIBRARY\n";
echo "\n";
/*
This is a boolean return. False essentially means
0; TMYK.
*/
return false;
}
else
return true; # Note the lack of curly brackets around this
# line of code. Amazing technology these days.
}
/**
* Stand back kiddies, this is how a real
* programmer does things.
*
**/
function main ( $argv )
{
// Enterprise usage of the count() function
// is demonstrated here, take note of the
// combined < and = symbol here, only a master
// programmer could have achieved such an
// operater without R(ing)TFM.
if ( count($argv) <= 1 )
{
// An excellent call to an undoubtedly elegant
// and not to mention genius display function.
usage();
exit; # Notice the multiple comment types in this file.
# The mark of a true programming genius.
}
// Simple and elegant usage of the master make_checks()
// library checking function, what would be referred to
// by a Java programmer as a Factory(lmfao Java).
if ( !make_checks() )
exit; # Sweet succulent success. NOT(lmfao!1)!
// The file to be derpafied.
$file = $argv[1];
# Only the technologically independent and savvy programmer
# will be able to truly understand the genius of the below
# statement; one that even William Shakespear could not have
# written better.
$type = ( substr($file, -4, 1) !== '.' ) // Can you see?
? substr($file, -4) // Can you see my genius.
: substr($file, -3) // It's shining...
; // oh so bright. What a marvelous function, I
// couldn't have done it better myself. Oh, wait.
echo $type, "\n";
}
main( $argv );
echo pathinfo($file)['extension']; // PHP 5.4
\$\endgroup\$