Hallo zusammen,
ich benutze schon seit einiger Zeit dieses Script um Bilder aus einem Ordner auszulesen. Das Problem dabei ist das ich die Bilder manuell in die Index.php eintragen muss damit diese aufgerufen werden.
Könnte man das Script den nicht so optimieren/umschreiben das zum Beispiel 10
Bilder zufällig aus dem Ordner geholt werden und anschließend in die index.php
geschrieben werden?
Danke schon mal im vorraus.
mfg
louna
Anbei die index.php
Hier die reflect.php die den Ordner ausliest.
ich benutze schon seit einiger Zeit dieses Script um Bilder aus einem Ordner auszulesen. Das Problem dabei ist das ich die Bilder manuell in die Index.php eintragen muss damit diese aufgerufen werden.
Könnte man das Script den nicht so optimieren/umschreiben das zum Beispiel 10
Bilder zufällig aus dem Ordner geholt werden und anschließend in die index.php
geschrieben werden?
Danke schon mal im vorraus.
mfg
louna
Anbei die index.php
PHP:
<?PHP
header("Expires: ".gmdate("D, d M Y H:i:s")." GMT"); // Always expired
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");// always modified
header("Cache-Control: no-cache, must-revalidate");// HTTP/1.1
header("Pragma: nocache");// HTTP/1.0
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title> Foto Show</title>
<link rel="shortcut icon" href="gfx/favicon.ico" type="image/x-icon">
<link rel="stylesheet" title="Standard" href="css/fotoflow.css" type="text/css" media="screen" />
<link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" />
<!--[if gte IE 5]><link rel="stylesheet" title="Standard" href="css/ie_hack.css" type="text/css" media="screen" /><![endif]-->
<script src="js/fotoflow.js" type="text/javascript"></script>
<script src="js/prototype.js" type="text/javascript"></script>
<script src="js/scriptaculous.js?load=effects" type="text/javascript"></script>
<script src="js/lightbox.js" type="text/javascript"></script>
<meta http-equiv="pragma" content="no-cache">
</head>
<body>
<div id="main">
<div id="fotoflow">
<div id="preloader">
<p><b>loading fotos</b></p>
<img src="gfx/loading_sm.gif" width="16" height="16" alt="loading" />
<img style="margin: 8px 8px 0px 8px;" src="gfx/loading.gif" width="32" height="32" alt="loading" />
<img src="gfx/loading_sm.gif" width="16" height="16" alt="loading" />
</div>
<div id="captions"></div>
<div id="fotos">
<img src="reflect.php?img=img/beach_01.jpg" lbox="javascript:myLightbox.start('img/beach_01.jpg|Beach 1');" alt="Beach 1" />
<img src="reflect.php?img=img/beach_02.jpg" lbox="javascript:myLightbox.start('img/beach_02.jpg|Beach 2');" alt="Beach 2" />
<img src="reflect.php?img=img/room_01.jpg" lbox="javascript:myLightbox.start('img/room_01.jpg|Guest Room 1');" alt="Guest Room 1" />
<img src="reflect.php?img=img/room_02.jpg" lbox="javascript:myLightbox.start('img/room_02.jpg|Guest Room 2');" alt="Guest Room 2" />
<img src="reflect.php?img=dbimage.php?imagen" lbox="javascript:myLightbox.start('img/wedding_01.jpg|Wedding 1');" alt="Wedding 1" />
<img src="reflect.php?img=img/wedding_02.jpg" lbox="javascript:myLightbox.start('img/wedding_02.jpg|Wedding 2');" alt="Wedding 2" />
<img src="reflect.php?img=img/nature_01.jpg" lbox="javascript:myLightbox.start('img/nature_01.jpg|Nature 1');" alt="Nature 1" />
<img src="reflect.php?img=img/nature_02.jpg" lbox="javascript:myLightbox.start('img/nature_02.jpg|Nature 2');" alt="Nature 2" />
<img src="reflect.php?img=img/xmas_01.jpg" lbox="javascript:myLightbox.start('img/xmas_01.jpg|Christmas 1');" alt="Christmas 1" />
<img src="reflect.php?img=img/xmas_02.jpg" lbox="javascript:myLightbox.start('img/xmas_02.jpg|Christmas 2');" alt="Christmas 2" />
<img src="reflect.php?img=img/food_01.jpg" lbox="javascript:myLightbox.start('img/food_01.jpg|Entrée 1');" alt="Entrée 1" />
<img src="reflect.php?img=img/dessert_01.jpg" lbox="javascript:myLightbox.start('img/dessert_01.jpg|Dessert 1');" alt="Dessert 1" />
<img src="reflect.php?img=img/food_02.jpg" lbox="javascript:myLightbox.start('img/food_02.jpg|Entrée 2');" alt="Entrée 2" />
<img src="reflect.php?img=img/dessert_02.jpg" lbox="javascript:myLightbox.start('img/dessert_02.jpg|Dessert 2');" alt="Dessert 2" />
</div>
<div id="scrollbar">
<div id="slider"></div>
</div>
</div>
</div>
</body>
<head>
<meta http-equiv="pragma" content="no-cache">
</head>
</html>
Hier die reflect.php die den Ordner ausliest.
PHP:
<?php
/*
This script accepts the following $_GET parameters:
img required The source image (to reflect)
height optional Height of the reflection (% or pixel value)
bgc optional Background colour to fade into, default = #000000
fade_start optional Start the alpha fade from whch value? (% value)
fade_end optional End the alpha fade from whch value? (% value)
jpeg optional Output will be JPEG at 'param' quality (default 80)
cache optional Save reflection image to the cache? (boolean)
*/
// Replace special chars to be HTML-Code
$_GET['bgc'] = '#ffffff';
function stringToHTML($string)
{
$array_search = array('é', 'è', 'ë', 'ê', 'à', 'ä', 'Ä', 'â', 'ù', 'ü', 'Ü', 'û', 'ö', 'Ö', 'ô', 'ï', 'î');
$array_replace = array('é', 'è', 'ë', 'ê', 'à', 'ä', 'Ä', 'â', 'ù', 'ü', 'Ü', 'û', 'ö', 'Ö', 'ô', 'ï', 'î');
$string_return = str_replace($array_search, $array_replace, $string);
return $string_return;
}
// CACHE! EVERYTHING!
$_GET['cache'] = 0;
// PHP Version sanity check
if (version_compare('4.3.2', phpversion()) == 1)
{
echo 'This version of PHP is not fully supported. You need 4.3.2 or above.';
exit();
}
// GD check
if (extension_loaded('gd') == false && !dl('gd.so'))
{
echo 'You are missing the GD extension for PHP, sorry but I cannot continue.';
exit();
}
// Our allowed query string parameters
// To cache or not to cache? that is the question
if (isset($_GET['cache']))
{
if ((int) $_GET['cache'] == 1)
{
$cache = true;
}
else
{
$cache = false;
}
}
else
{
$cache = false;
}
// img (the image to reflect)
if (isset($_GET['img']))
{
$source_image = $_GET['img'];
//$source_image = utf8_decode($source_image);
$source_image = str_replace('://','',$source_image);
//$source_image = $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . $source_image;
if (file_exists($source_image))
{
if ($cache)
{
$cache_dir = dirname($source_image);
$cache_base = basename($source_image);
$cache_file = 'refl_' . md5($_SERVER['REQUEST_URI']) . '_' . $cache_base;
$cache_path = $cache_dir . DIRECTORY_SEPARATOR . $cache_file;
if (file_exists($cache_path) && filemtime($cache_path) >= filemtime($source_image))
{
// Use cached image
$image_info = getimagesize($cache_path);
header("Content-type: " . $image_info['mime']);
readfile($cache_path);
exit();
}
}
}
else
{
echo 'Cannot find or read source image';
exit();
}
}
else
{
echo 'No source image to reflect supplied';
exit();
}
// bgc (the background colour used, defaults to black if not given)
if (isset($_GET['bgc']) == false)
{
$red = 0;
$green = 0;
$blue = 0;
}
else
{
// Extract the hex colour
$hex_bgc = $_GET['bgc'];
// Does it start with a hash? If so then strip it
$hex_bgc = str_replace('#', '', $hex_bgc);
switch (strlen($hex_bgc))
{
case 6:
$red = hexdec(substr($hex_bgc, 0, 2));
$green = hexdec(substr($hex_bgc, 2, 2));
$blue = hexdec(substr($hex_bgc, 4, 2));
break;
case 3:
$red = substr($hex_bgc, 0, 1);
$green = substr($hex_bgc, 1, 1);
$blue = substr($hex_bgc, 2, 1);
$red = hexdec($red . $red);
$green = hexdec($green . $green);
$blue = hexdec($blue . $blue);
break;
default:
// Wrong values passed, default to black
$red = 0;
$green = 0;
$blue = 0;
}
}
// height (how tall should the reflection be?)
if (isset($_GET['height']))
{
$output_height = $_GET['height'];
// Have they given us a percentage?
if (substr($output_height, -1) == '%')
{
// Yes, remove the % sign
$output_height = (int) substr($output_height, 0, -1);
// Gotta love auto type casting ;)
if ($output_height < 10)
{
$output_height = "0.0$output_height";
}
else
{
$output_height = "0.$output_height";
}
}
else
{
$output_height = (int) $output_height;
}
}
else
{
// No height was given, so default to 50% of the source images height
$output_height = 0.50;
}
if (isset($_GET['fade_start']))
{
if (strpos($_GET['fade_start'], '%') !== false)
{
$alpha_start = str_replace('%', '', $_GET['fade_start']);
$alpha_start = (int) (127 * $alpha_start / 100);
}
else
{
$alpha_start = (int) $_GET['fade_start'];
if ($alpha_start < 1 || $alpha_start > 127)
{
$alpha_start = 80;
}
}
}
else
{
$alpha_start = 80;
}
if (isset($_GET['fade_end']))
{
if (strpos($_GET['fade_end'], '%') !== false)
{
$alpha_end = str_replace('%', '', $_GET['fade_end']);
$alpha_end = (int) (127 * $alpha_end / 100);
}
else
{
$alpha_end = (int) $_GET['fade_end'];
if ($alpha_end < 1 || $alpha_end > 0)
{
$alpha_end = 0;
}
}
}
else
{
$alpha_end = 0;
}
/*
----------------------------------------------------------------
Ok, let's do it ...
----------------------------------------------------------------
*/
// How big is the image?
$image_details = getimagesize($source_image);
if ($image_details === false)
{
echo 'Not a valid image supplied, or this script does not have permissions to access it.';
exit();
}
else
{
$width = $image_details[0];
$height = $image_details[1];
$type = $image_details[2];
$mime = $image_details['mime'];
}
// Calculate the height of the output image
if ($output_height < 1)
{
// The output height is a percentage
$new_height = $height * $output_height;
}
else
{
// The output height is a fixed pixel value
$new_height = $output_height;
}
// Detect the source image format - only GIF, JPEG and PNG are supported. If you need more, extend this yourself.
switch ($type)
{
case 1:
// GIF
$source = imagecreatefromgif($source_image);
break;
case 2:
// JPG
$source = imagecreatefromjpeg($source_image);
break;
case 3:
// PNG
$source = imagecreatefrompng($source_image);
break;
default:
echo 'Unsupported image file format.';
exit();
}
/*
----------------------------------------------------------------
Build the reflection image
----------------------------------------------------------------
*/
// We'll store the final reflection in $output. $buffer is for internal use.
$output = imagecreatetruecolor($width, $new_height);
$buffer = imagecreatetruecolor($width, $new_height);
// Copy the bottom-most part of the source image into the output
imagecopy($output, $source, 0, 0, 0, $height - $new_height, $width, $new_height);
// Rotate and flip it (strip flip method)
for ($y = 0; $y < $new_height; $y++)
{
imagecopy($buffer, $output, 0, $y, 0, $new_height - $y - 1, $width, 1);
}
$output = $buffer;
/*
----------------------------------------------------------------
Apply the fade effect
----------------------------------------------------------------
*/
// This is quite simple really. There are 127 available levels of alpha, so we just
// step-through the reflected image, drawing a box over the top, with a set alpha level.
// The end result? A cool fade into the background colour given.
// There are a maximum of 127 alpha fade steps we can use, so work out the alpha step rate
$alpha_length = abs($alpha_start - $alpha_end);
for ($y = 0; $y <= $new_height; $y++)
{
// Get % of reflection height
$pct = $y / $new_height;
// Get % of alpha
if ($alpha_start > $alpha_end)
{
$alpha = (int) ($alpha_start - ($pct * $alpha_length));
}
else
{
$alpha = (int) ($alpha_start + ($pct * $alpha_length));
}
imagefilledrectangle($output, 0, $y, $width, $y, imagecolorallocatealpha($output, $red, $green, $blue, $alpha));
}
/*
----------------------------------------------------------------
HACK - Build the reflection image by combining the source
image AND the reflection in one new image!
----------------------------------------------------------------
*/
$finaloutput = imagecreatetruecolor($width, $height+$new_height);
imagecopy($finaloutput, $source, 0, 0, 0, 0, $width, $height);
imagecopy($finaloutput, $output, 0, $height, 0, 0, $width, $new_height);
$output = $finaloutput;
/*
----------------------------------------------------------------
Output our final PNG
----------------------------------------------------------------
*/
if (headers_sent())
{
echo 'Headers already sent, I cannot display an image now. Have you got an extra line-feed in this file somewhere?';
exit();
}
else
{
// If you'd rather output a JPEG instead of a PNG then pass the parameter 'jpeg' (no value needed) on the querystring
if (isset($_GET['png']))
{
// PNG
header("Content-type: image/png");
imagepng($output);
// Save cached file
if ($cache)
{
imagepng($output, $cache_path);
}
}
else
{
if(!isset( $_GET['jpeg'])) $_GET['jpeg'] = 90;
$quality = (int) $_GET['jpeg'];
if ($quality < 1 || $quality > 100)
{
$quality = 90;
}
// JPEG (the final parameter = the quality, 0 = terrible, 100 = pixel perfect)
header("Content-type: image/jpeg");
imagejpeg($output, '', $quality);
// Save cached file
if ($cache)
{
imagejpeg($output, $cache_path, $quality);
}
}
imagedestroy($output);
exit();
}
?>
Zuletzt bearbeitet: