Kiedyś napisałem takie coś co zmniejszało obrazki, jak chcesz to możesz sobie to przerobić.
Struktura katalogów:
+ sktypt
- images (dir )
- config.php
- image.php
- index.php
A teraz pliki:
config.php
<?php
function FindFiles($dir)
{
if ( !$katalog )
{
return false;
}
while ( ( $file = readdir( $katalog ) ) !== false ) {
if ( !( $file=='.' || $file == '..' ) )
{
}
}
return $files;
}
?>
image.php
<?php
require_once('config.php');
if ( strpos($img_name, 'jpg') != 0
) {
$img = imagecreatefromjpeg(IMG_DIR.'/'.$img_name);
$img_type = 'jpg';
}
elseif ( strpos($img_name, 'png') != 0
) {
$img = imagecreatefrompng(IMG_DIR.'/'.$img_name);
$img_type = 'png';
}
elseif ( strpos($img_name, 'gif') != 0
) {
$img = imagecreatefromgif(IMG_DIR.'/'.$img_name);
$img_type = 'gif';
}
$img_w = imagesx($img); //szerokość obrazka
$img_h = imagesy($img); //wysokość obrazka
$ratio = $img_w / $img_h;
if ( $ratio > 1 )
{
$new_img_w = SIZE;
$new_img_h = ( SIZE / $ratio);
}
else
{
$new_img_w = ( SIZE * $ratio);
$new_img_h = SIZE;
}
$temp_img = imagecreatetruecolor($new_img_w, $new_img_h);
imagecopyresized($temp_img, $img, 0, 0, 0, 0, $new_img_w, $new_img_h, $img_w, $img_h);
switch ( $img_type )
{
case 'jpg': header(\"Content-type: image/jpeg\"); case 'gif': header(\"Content-type: image/gif\"); case 'png': header(\"Content-type: image/png\"); }
header(\"Cache-Control: post-check=0, pre-check=0\", false); header(\"Pragma: no-cache\");
switch ( $img_type )
{
case 'jpg': imagejpeg($temp_img);
case 'gif': imagegif($temp_img);
case 'png': imagepng($temp_img);
}
ImageDestroy($img);
ImageDestroy($temp_img);
?>
index.php
<?php
require_once('config.php');
if($_GET['action'] != 'jeden')
{
$pliki = FindFiles(IMG_DIR);
echo '<table border=\"1\" align=\"center\">';
for($i = 1; $i <= sizeof($pliki); $i++) {
echo '<td align=\"center\">'; echo '<a href=\"index.php?action=jeden&img='.$pliki[$i-1].'\"><img src=\"image.php?img='.$pliki[$i-1].'\"></a>'; if ( ( $i % COLS ) == 0 )
{
}
}
}
else
{
echo '<a href=\"index.php\"><img src=\"'.IMG_DIR
.'/'.$_GET['img'].'\"></a>'; }
?>
No i teraz opis działania:
Skrypt skanuje folder images w poszukiwaniu plików z obrazkami i wyświetla ich miniaturki. Po kliknięciu w miniaturkę dostajemy oryginał.