Witam :-)
Mam skrypt własnej roboty, skrypt do miniaturek, lecz nie wiem jak go zmodyfikować, zeby w zmiennej $obrazek przechowywać cały obrazek np. $obrazek=zdjecie.jpg.
Aktualnie skryptu używa się tak:
<img border="0" src="skrypt.php?id=$id&type=$roz_pliku">
Gdzie $id = id pliku (nazwa) a $type = rozszerzenie pliku.
<?php
<?php
// Katalog z obrazkami (nazwa obrazku to $id.$type, $id - liczba, $type
// - jeden z [gif, png, jpg, jpeg])
$img_dir = '/img/';
// Prefiks miniatur
$thumb_prefix = 'mini_';
// Katalog z miniaturami
$thumb_dir = 'mini/';
// Automatyczne wykrywanie zmiany oryginalnego pliku, nie zawsze działa
// Żeby sprawdzić, czy działa, sprawdĽ czy daty utworzenia oryginalnego pliku
// i jego miniatury s± takie same.
// Je¶li wył±czone, nie zapomnij po zmianie oryginalnego pliku usun±ć
// miniatury!!!
$auto_detect = true;
function generate_thumbnail($srcFile, $destFile, $maxWidth = 98, $maxHeight = 98, $quality = 75, $forceJPEG = false)
{
$width = $info[0];
$height = $info[1];
$imgType = $info[2];
$xRatio = $maxWidth / $width;
$yRatio = $maxHeight / $height;
if( ($width <= $maxWidth) && ($height <= $maxHeight) ) {
$newWidth = $width;
$newHeight = $height;
}
elseif( ($xRatio * $height) < $maxHeight ) {
$newHeight = ceil($xRatio * $height); $newWidth = $maxWidth;
}
else {
$newWidth = ceil($yRatio * $width); $newHeight = $maxHeight;
}
{
}
if( (!$forceJPEG || ($forceJPEG && $imgType == IMAGETYPE_JPEG)) && $newWidth == $width && $newHeight == $height )
{
if( copy($srcFile, $destFile) ) {
@chmod($destFile, 0666);
return true;
}
else
{
return false;
}
}
switch( $imgType )
{
case IMAGETYPE_GIF:
$img = ImageCreateFromGif($srcFile);
break;
case IMAGETYPE_JPEG:
$img = ImageCreateFromJpeg($srcFile);
break;
case IMAGETYPE_PNG:
$img = ImageCreateFromPng($srcFile);
break;
default:
die(\"Sorry, this image type ($img_type) is not supported\"); }
$thumb = ImageCreateTrueColor($newWidth, $newHeight);
ImageCopyResampled($thumb, $img, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height);
ImageDestroy($img);
if( $forceJPEG || $imgType == IMAGETYPE_JPEG )
{
$return_val = ImageJPEG($thumb, $destFile, $quality);
}
switch( $imgType )
{
case IMAGETYPE_GIF:
$return_val = ImageGIF($thumb, $destFile);
break;
case IMAGETYPE_PNG:
$return_val = ImagePNG($thumb, $destFile);
break;
}
@chmod($destFile, 0666);
ImageDestroy($thumb);
return true;
}
$img_file = isset($_GET['id']) ?
$_GET['id'] : false; if( !$img_file || !preg_match('/[a-z0-9]+/', $img_file) ) {
}
$img_type = isset($_GET['type']) ?
$_GET['type'] : ''; if( !in_array($img_type, array('gif', 'png', 'jpg', 'jpeg', 'jpe', 'JPG', 'GIF' , 'PNG', 'BMP')) ) {
}
$filename = $img_file . '.' . $img_type;
$img_file = $img_dir . $filename;
$thumb_file = $thumb_dir . $thumb_prefix . $filename;
{
die('Given file does not exists'); }
{
generate_thumbnail($img_file, $thumb_file);
}
switch( $img_type )
{
case 'gif':
Header(\"Content-type: image/gif\"); break;
case 'png':
header(\"Content-type: image/png\"); break;
case 'jpg':
case 'jpeg':
header(\"Content-type: image/jpeg\"); break;
}
?>
Dzięki wielkie :-)