<?php
/*******************************************************
* image.sh.php *
* Thursday, April 05, 2001 *
* <brian@spamcop.net> *
* *
* The purpose of this php shell script is to take an *
* image and get it's dimensions using getimagesize(). *
* You must supply the base directory and the image's *
* name as the first two arguments. See "usage" *
* *
* The only thing static is the possbile path names. *
* Most people use names familiar to them, so change *
* those to suit your own mind. *
* *
* I use this script with TextPad and EditPlus. *
* Most good editors hold their own environmental *
* variables. *
* *
* In TextPad, I call this script using a keyboard *
* shortcut attached to a macro. I call it from *
* "Tools" like so: *
* *
* c:\php\php.exe -q image.sh.php $FileDir $Sel *
* *
* Note that $FileDir and $Sel are not php scalars; *
* they're internal variables unique to TextPad. Here, *
* I placed image.sh.php in my %PATH% ($PATH on Unix, *
* of course). *
* *
* Real world example: Let's say I have a document *
* that is being edited from c:\www\mysite. $FileDir *
* holds the current directory, without the trailing *
* slash. $Sel is the currently highlighted image *
* name. The output, in the TextPad command output *
* window is the full image tag with the base path, a *
* forward slash, and the image name - along with the *
* height and width and the optional alt tag taken as *
* a third argument (after $Sel, in quotes). *
*******************************************************/
$paths = array('images','pics','photos','.');
/* void buildImgTag(array array) */
buildImgTag($paths);
function buildImgTag($paths)
{
global $argv, $argc;
if($argc < 2)
{
print "\n\nNot enough arguments.\n";
print "Usage: $argv[0] -q [base directory] [image name]\n";
print "(-q is to supress the Content-type header)\n";
return;
}
$base = str_replace('\\','/',$argv[1]);
$filen = $argv[2];
$alt = $argv[3];
while(list($i,$path) = each($paths))
{
$image = implode('/',array($base,$path,$filen));
if($params = @getimagesize($image))
{
print "<img src=\"$path/$filen\" $params[3] ";
print "alt=\"$alt\" border=\"0\" />";
return;
}
}
return;
}
?>