Tu j ten script na fotky:
foto.php
Kód:
<?php
$directory = getcwd();
$directories = array();
getListOfDirectories( $directories, $directory );
// Max width of image thumbnail
$max_width = 180;
// Max height of image thumbnail
$max_height = 150;
// Max number of images per row of the table
$images_per_row = 2;
$directories = array_flip($directories);
foreach( $directories as $directory => $foo){
$directories[ $directory ] = array();
$directory_reader = dir($directory);
// Get a list of images
while (false !== ($filename = $directory_reader->read())) {
if( preg_match( "~.*\.(gif|jpg|jpeg|png)~Ui", $filename, $matches ) ){
$directories[ $directory ][] = $filename;
}
}
$directory_reader->close();
}
function getListOfDirectories( &$directories, $current_directory ){
$directories[] = $current_directory;
$directory_reader = dir($current_directory);
while (false !== ($filename = $directory_reader->read())) {
if( is_dir( $current_directory . '/' . $filename ) && $filename[0] != '.'){
getListOfDirectories( $directories, $current_directory . '/' . $filename );
}
}
}
?>
<table>
<?php
// Render the images in their rows
foreach( $directories as $directory => $images ){
$directory = substr( $directory, strlen( getcwd() ) + 1 );
echo (
str_replace
(
array(
'[[images_per_row]]',
'[[directory_name]]',
),
array(
$images_per_row,
($directory)?$directory:'[[current]]'
),
''
)
);
$rows = ceil(count($images)/$images_per_row);
for( $y = 0; $y < $rows; $y++ ){
echo( '<tr>' );
for( $x = 0; $x < $images_per_row; $x++ ){
$index = $x + ( $y * $images_per_row );
if( $index < count( $images ) ){
echo
(
str_replace
(
array(
'[[path]]',
'[[image_name]]',
'[[width]]',
'[[height]]'
),
array(
(($directory)?$directory.'/':''),
$images[ $index ],
$max_width,
$max_height
),
'<td align="center"><a href="[[path]][[image_name]]" rel="lightbox[roadtrip]"><img border="0" src="get_image.php?image_name=[[path]][[image_name]]&width=[[width]]&height=[[height]]" alt="[[image_name]]"></a></td>'
)
);
}
}
echo( '</tr>' );
}
}
?>
</table>
get_image.php
Kód:
<?php
$image_name = './' . $_GET[ 'image_name' ];
$output_width = $_GET[ 'width' ];
$output_height = $_GET[ 'height' ];
$types = array(
'jpeg' => 'image/jpeg',
'gif' => 'image/gif',
'png' => 'image/png',
);
if( preg_match( "~.*\.(gif|jpg|jpeg|png)~Ui", $image_name, $matches ) ){
$format = $matches[ 1 ];
if( $format == 'jpg' ){
$format = 'jpeg';
}
switch( $format ){
case 'gif':{
$image = imagecreatefromgif( $image_name );
break;
}
case 'jpeg':{
$image = imagecreatefromjpeg( $image_name );
break;
}
case 'png':{
$image = imagecreatefrompng( $image_name );
break;
}
}
// obtain source image dimensions
list( $width, $height, $type ) = getimagesize( $image_name );
// By default, w/h are the same as the requested output size
$new_height = $output_height;
$new_width = $output_width;
// Do we have to shrink it horizontally or vertically?
$ratio_current = $width / $height;
$ratio_output = $output_width / $output_height;
if( $ratio_current > $ratio_output ){
// New ratio is wider/shorter than old
$new_height = $height / ( $width / $output_width );
} elseif ( $ratio_current < $ratio_output ) {
// New ratio is taller/thinner than old
$new_width = $width / ( $height / $output_height );
}
// Create a blank image
$target = imagecreatetruecolor
(
$new_width,
$new_height
);
// Copy resized image into blank image
imagecopyresampled( $target, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
// Clean up in-memory objects
imagedestroy( $image );
header("Content-Type: " . $types[ $format ]);
imagejpeg($target);
}
?>
Ten script je tak urobeny, ze berie fotky z tamadial, kde sa to .php nachaza. Mohol by mi to niekto upravit, ze sa na tvrdo nastavi priecinok?
Dakujem