Tuesday, December 25, 2007

PHP CLI image size calculator

<source_code>
#!/usr/bin/php
<?php
fwrite(STDOUT, "Please enter the URL directory 
path of the files: \n");
$host_dir = fgets(STDIN);
fwrite(STDOUT, "Please enter the sizing number:\n");
$sizeimg = fgets(STDIN);
$list_of_files = array();
exec(ls, &$list_of_files);
foreach ($list_of_files as $image) {
$size = getimagesize($image);
$width = $size[0]; // Index 0
$height = $size[1]; // Index 1
$type = $size[2]; // Index 2
$nwidth=$width*${sizeimg};
$nheight=$height*${sizeimg};
echo "\n<a href=\"".${host_dir}.${image}."\">
     <img src=\"".${host_dir}.${image}."\" 
     width=\"".$nwidth."\"
     height=\"".$nheight."\" ></img>\n";
echo "</a><br /><br />";
}
echo "\n";
?>
</source_code>

No comments: