I could also paste them here, for you to use:
function resize($imagedata, $thumbsize=90, $size_axis=false)
{
// resizes image so that $size_axis == $thumbsize . If $size_axis is not properly set then it will pick the biggest of x,y
// possible values for $size_axis : 'x', 'y' (anything else is equivalent to "autodetection")
// $imagedata is a string containing the image binary data (can be of any type supported by gd2: jpeg, gif, etc..)
// function returns a string containing the binary data of the thumbnail compressed as JPEG, or false if something goes wrong.
extension_loaded('gd') or dl("php_gd2");
// load image
$image = imagecreatefromstring($imagedata);
$imagewidth = imagesx($image);
$imageheight = imagesy($image);
// choose x or y axis
if ($size_axis!='x' and $size_axis!='y') {
// automatic detection of the biggest axis
if ( $imagewidth > $imageheight) {
$size_axis = 'x';
} else {
$size_axis = 'y';
}
}
// calculate resize ratio
if ($size_axis == 'x') {
// x is set
$thumbwidth = $thumbsize;
$factor = $thumbsize / $imagewidth;
$thumbheight = (int) ($imageheight * $factor);
} else {
// y is set
$thumbheight = $thumbsize;
$factor = $thumbsize / $imageheight;
$thumbwidth = (int) ($imagewidth * $factor);
}
// generate thumbnail
$thumb = imagecreatetruecolor($thumbwidth,$thumbheight);
imagecopyresampled($thumb, $image, 0, 0, 0, 0, $thumbwidth, $thumbheight, $imagewidth, $imageheight);
// compress and return (imagejpeg() outputs to the browser, so we need to catch the output with ob_)
ob_start();
if( imagejpeg($thumb) ) {
$thumbdata = ob_get_contents();
ob_end_clean();
imagedestroy($image);
imagedestroy($thumb);
return $thumbdata;
} else {
ob_end_clean();
return false;
}
}
Now for FS functions:
function get_files($path, $regex = false) {
$d = dir($path);
while ( $entry = $d->read() ) {
$current = "$path/$entry";
if (is_file($current) and ($regex === false or preg_match($regex, $entry )) ) {
$ret[]=$current;
}
}
$d->close();
return $ret;
}
function get_subdirs($path, $regex = false) {
$d = dir($path);
while ( $entry = $d->read() ) {
$current = "$path/$entry";
if (is_dir($current) and ($regex === false or preg_match($regex, $entry )) ) {
$ret[]=$current;
}
}
$d->close();
return $ret;
}
Example of usage for the filesystem functions:
<?php
foreach( get_files('img/work','/^kitabat_.+\.(jpg|jpeg|gif|png)$/') as $image ) {
echo "<img class=\"screenie\" src=\"$image\">";
}
?>
YOU NOW OWE ME A BEER. A big one. Draft.
:-)