Builder.cz - Informacni server o programovani

Odběr fotomagazínu

Fotografický magazín "iZIN IDIF" každý týden ve Vašem e-mailu.
Co nového ve světě fotografie!

 

Zadejte Vaši e-mailovou adresu:

Kamarád fotí rád?

Přihlas ho k odběru fotomagazínu!

 

Zadejte e-mailovou adresu kamaráda:



Re: Automatické náhledy

Seznam témat     Nová odpověď

Přihlásit se     Registrace     Zapomenuté heslo

Re: Automatické náhledy

Autor: JohnyB

20:43:12 25.06.2003

Tohle sem vyhrab na disku:

// Byl uz formular odeslan?
if ($send && $userfile)
{
function file_upload_handling ($ifile_name, $inew_name)
{ // povolene koncovky souboru
$allowed = array ('.jpg','.gif','.jpeg','.bmp');
$extenze=strrchr($ifile_name['name'], ".");
// je tato koncovka povolena?
if (in_array (strtolower ($extenze), $allowed))
{ // nazev noveho souboru
$filename = $inew_name.$extenze;
// stahnuty/na netu?
if (substr(strtolower($ifile_name['name']),0,7) != "http://")
move_uploaded_file ($ifile_name['tmp_name'], $filename);
else
{ // zalozime 1
$file1 = FOpen ($filename, "w+");
// otevreme 2
$file2 = FOpen ($ifile_name['name'], "r");
// precteme 2
while (!feof ($file2))
$obsah .= fgetc ($file2);
// zapiseme 2 do 1
fwrite ($file1, $obsah);
// zavreme 1
fclose ($file1);
}
// zmenime mu prava
chmod ($filename, 0666);
return $filename;
}
}

function saveThumbnail ($fpath, $output_fn, $outputtype = "gif", $outputquality = 100)
{ /* GetImageSize returns an array:
* $info[0] - horizontal size of image in pixels
* $info[1] - vertical size of image in pixels
* $info[2] - type of image (1=GIF, 2=JPEG, 3=PNG)
*/
$info = GetImageSize($fpath);

// do we need to resize? (file width set to 150, file height recalculates to match x:y ratio)
if ($info[1] > 150)
{ $width = 150;
$height = floor (150 / $info[0] * $info[1]);
}
else
{ $width = $info[0];
$height = $info[1];
}

// create new thumbnail image (use imagecreatetruecolor with 2.0 lib for jpegs!)
$im = ImageCreate ($width, $height);

// determine image type and load original image. Notice new tests for image
// types. The GD extension has changed a lot over the years, dropping GIFs
// and adding PNG support. By testing, we avoid trying to process an image
// PHP can't deal with

switch ($info[2])
{ case 1 : if (ImageTypes() & IMG_GIF) // test for GIF support
$im_big = ImageCreateFromGIF("$fpath");
break;
case 2 : if (ImageTypes() & IMG_JPG) // test for JPEG support
$im_big = ImageCreateFromJPEG("$fpath");
break;
case 3 : if (ImageTypes() & IMG_PNG) // test for PNG support
$im_big = ImageCreateFromPNG("$fpath");
break;
}

if ($im_big)
{
// resize original image into thumbnail (use resampled with 2.0 lib, in other case try resized)
imagecopyresampled($im, $im_big, 0, 0, 0, 0, $width, $height, $info[0], $info[1]);
}
else
{
$badphoto=2;

// in case creating of thumbnail fails, this will create blank image with text "No thumbnail available"
/* $width = 150;
* $height = 100;
* $im = ImageCreate($width, $height);
* $bgc = ImageColorAllocate($im, 0, 0, 0);
* $tc = ImageColorAllocate($im, 255, 255, 255);
* ImageFilledRectangle($im, 0, 0, $width, $height, $bgc);
* ImageString($im, 3, 9, 36, "No thumbnail", $tc);
* ImageString($im, 3, 17, 48, "available", $tc);
*/
}

// name of output file
$resfile = $output_fn.".".$outputtype;
if (file_exists ($resfile))
unlink ($resfile);

// save output file
if ($badphoto != 2)
{ switch ($outputtype)
{ case "gif" : ImageGIF($im, $resfile);
break;
case "jpg" : ImageJPEG($im, $resfile, $outputquality);
break;
}

// clean up memory
ImageDestroy($im_big);
ImageDestroy($im);

// returns name of output file with extension
return ($resfile);
}
else
return false;
}

$uploadedfile = file_upload_handling ($HTTP_POST_FILES['userfile'], "temp");
$resfile = saveThumbnail($uploadedfile, "th_temp", $dest_type, $dest_qual);
}
?>



Infopoint.cz




if ($resfile)
echo "Vysledek: source/thumbnail, velikost ". number_format (filesize ($resfile), 0, " ", " ");
?>




echo "\n ";
echo "\n ";
?>

Obrazek:
Vystupni format:
Kvalita (jen pro JPEG):


echo "
";
?>

"; echo "\n "; ?>
Obrazek:
Vystupni format:
Kvalita (jen pro JPEG):
"; ?>

Citovat příspěvek

 

 

 

Přihlášení k mému účtu

Uživatelské jméno:

Heslo: