#!/usr/bin/env php # # Revision History # 1.0 Initial revision. 150119 # 1.1 Added the -man and -Version options. 150401 # 1.2 Fixed for unrecognized file types, no arguments, 160126 # and to use env as the shebang path. # 1.3 Added licensing info. 180616 # # Copyright 2015 Wayne Morrison # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # # Version information. # $NAME = "imgsize"; $VERS = "$NAME version: 1.3"; main(); exit(0); #------------------------------------------------------------------------ # Routine: main() # function main() { global $argv; # # Check for an option. # doopts($argv[1]); # # Ensure we were given files to check. # if(sizeof($argv) == 1) { usage(1); } # # Give the width x height dimensions of a set of image files. # for($ind = 1; $ind < sizeof($argv); $ind++) { $fn = $argv[$ind]; # # Ensure the file actually exists. # if(stat($fn) == '') { print "$fn: could not find\n"; continue; } # # Get the size of the file's image. # $arr = getimagesize($fn); # # Give the appropriate message for the file. # if(sizeof($arr) > 1) { print "$fn: $arr[0] x $arr[1] \n"; } else { print "$fn: unable to determine image size\n"; } } } #------------------------------------------------------------------------ # Routine: doopts() # # Purpose: Handle our options: -help, -man, -Version. # function doopts($arg) { # # Return if the first argument doesn't start with a dash. # if($arg[0] != "-") { return; } if(($arg == "-h") || ($arg == "-he") || ($arg == "-hel") || ($arg == "-help")) { usage(0); } elseif(($arg == "-m") || ($arg == "-ma") || ($arg == "-man")) { manpage(); } elseif(($arg == "-V") || ($arg == "-Ve") || ($arg == "-Ver") || ($arg == "-Vers") || ($arg == "-Versi") || ($arg == "-Versio") || ($arg == "-Version")) { global $VERS; print "$VERS\n"; } else { print "unrecognized option \"$argv[1]\"\n"; exit(1); } exit(0); } #------------------------------------------------------------------------ # Routine: usage() # function usage($rc) { print "usage: imgsize [-help | -man | -Version] \n"; exit($rc); } #------------------------------------------------------------------------ # Routine: manpage() # function manpage() { print " NAME imgsize - give the dimensions of a set of image files SYNOPSIS imgsize [-help | -man | -Version] DESCRIPTION imgsize gives the width x height dimensions of the named image files. OPTIONS imgsize takes the following options: -help Display a help message. -man Display this man page. -Version Display the version information for imgsize. Copyright 2015 Wayne Morrison Licensed under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. AUTHOR Wayne Morrison, wayne@waynemorrison.com "; } ?>