function process_picture ($pararr)
{
global $dbconnect;
$file = $pararr['file'];
$navpath = $pararr['navpath'];
$height = empty ($pararr['height']) ? 400 : intval($pararr['height']);
$self = $params['self'];
if (empty ($file))
return divWrapper ("Missing Picture File");
$next = getNext($navpath, $file);
$prev = getPrev($navpath, $file);
// Get picture scaled to height as base 64 string
$b64 = scaleImageToBase64 ($file, $height);
// Create table cell
$result = "";
$result .= "
$result = "
\r\n";
$result .= "\r\n";
// if a title is defined, display it
if (!empty($title))
{
$result .= "
$title
\r\n";
$result .= "\r\n";
}
// Process all pictures
//foreach (glob($path, GLOB_NOSORT) as $image)
foreach (glob($path, 0) as $image)
{
// Get name
$name = basename($image, ".jpg");
$title = substr($name, 4);
// Get cell height
$cellheight = $height + 40;
// Get picture scaled to height as base 64 string
$b64 = scaleImageToBase64 ($image, $height);
// Create table cell
$result .= "
";
$result .= "

\r\n";
$result .= "
$title";
$result .= "
";
// Create horizontal separator
$result .= " ";
}
$result .= "
\r\n";
// Close picture galery div
$result .= "\r\n";
$result .= "
\r\n";
$result .= "\r\n";
return $result;
}
function scaleImageToBase64 ($file, $height)
{
$source_image = imagecreatefromjpeg($file);
$source_imagex = imagesx($source_image);
$source_imagey = imagesy($source_image);
$dest_imagex = $source_imagex * $height / $source_imagey;
//$dest_imagex = $height * 2 / 3;
$dest_imagey = $height;
$dest_image = imagecreatetruecolor($dest_imagex, $dest_imagey);
imagecopyresampled($dest_image, $source_image, 0, 0, 0, 0, $dest_imagex, $dest_imagey, $source_imagex, $source_imagey);
ob_start(); //Start output buffer.
imagejpeg($dest_image); //This will normally output the image, but because of ob_start(), it won't.
$contents = ob_get_contents(); //Instead, output above is saved to $contents
ob_end_clean(); //End the output buffer.
return base64_encode($contents);
}
function getNext($navpath, $file)
{
if (empty($navpath) || empty ($file))
return "";
$a = glob ($navpath, 0);
//$a = glob ($navpath, GLOB_NOSORT);
$count = count($a);
for ($k=0; $k<$count-1; $k++)
if ($a[$k] == $file)
return $a[$k+1];
return "";
}
function getPrev($navpath, $file)
{
if (empty($navpath) || empty ($file))
return "";
$a = glob ($navpath, 0);
//$a = glob ($navpath, GLOB_NOSORT);
$count = count($a);
for ($k=1; $k<$count; $k++)
if ($a[$k] == $file)
return $a[$k-1];
return "";
}
?>
Red Velvet