script © 2013 by webdesign weisshart |
Automatisch Umwandlung in Thumbnails |
So sieht´s aus |
Sehen tun Sie hier nichts. Dieses Script wandelt einen festgelegten Ordner mit Bildern verschiedener Größen automatisch in Thumbnail einer festgesetzten Größe um. So sieht der Upload aus ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Quellcode |
<html>
<head> <style type="text/css">Hier nichts</style> </head> <body > <?Php //*************************************** // This is downloaded from www.plus2net.com // /// You can distribute this code with the link to www.plus2net.com /// // Please don't remove the link to www.plus2net.com /// // This is for your learning only not for commercial use. /////// //The author is not responsible for any type of loss or problem or damage on using this script.// /// You can use it at your own risk. ///// //***************************************** ?> <FORM ENCTYPE="multipart/form-data" ACTION="Thumbnail Bild erstellen.php" METHOD=POST> Eine <INPUT NAME="userfile" TYPE="file"> <INPUT TYPE="submit" VALUE="Datei jetzt hochladen"></FORM> <?Php echo "Name der Uploaddatei: ".$_FILES['userfile']['name']."<br>"; echo "Name der Speicherdatei: ".$_FILES['userfile']['tmp_name']."<br>"; echo "Datei Type: ".$_FILES['userfile']['type']."<br>"; echo "<br><br>"; $add="upimg/".$_FILES['userfile']['name']; if(move_uploaded_file ($_FILES['userfile']['tmp_name'],$add)){ echo "Erfolgreich hochgeladen: "; chmod("$add",0777); } else { echo "Upload leider fehlgeschlagen"; exit; } $n_width=200; // Fix the width of the thumb nail images $n_height=200; // Fix the height of the thumb nail imaage $tsrc="thimg/".$_FILES['userfile']['name']; // Path where thumb nail image will be stored if (!($_FILES['userfile']['type'] =="image/jpeg" OR $_FILES['userfile']['type']=="image/gif")){echo "Ihre Bilddatei MUSS JPG oder GIF sein.<BR>"; exit;} if (@$_FILES['userfile']['type']=="image/gif") { $im=ImageCreateFromGIF($add); $width=ImageSx($im); // Original picture width is stored $height=ImageSy($im); // Original picture height is stored $n_height=($n_width/$width) * $height; // Add this line to maintain aspect ratio $newimage=imagecreatetruecolor($n_width,$n_height); imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height); if (function_exists("imagegif")) { Header("Content-type: image/gif"); ImageGIF($newimage,$tsrc); } elseif (function_exists("imagejpeg")) { Header("Content-type: image/jpeg"); ImageJPEG($newimage,$tsrc); } chmod("$tsrc",0777); } if($_FILES['userfile']['type']=="image/jpeg"){ $im=ImageCreateFromJPEG($add); $width=ImageSx($im); // Original picture width is stored $height=ImageSy($im); // Original picture height is stored $n_height=($n_width/$width) * $height; // Add this line to maintain aspect ratio $newimage=imagecreatetruecolor($n_width,$n_height); imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height); ImageJpeg($newimage,$tsrc); chmod("$tsrc",0777); } echo "Breite = ($width) $n_width , Höhe = ($height) $n_height "; ?> <br/><br/> Dieses Thumbnail haben Sie erzeugt<br/><br/> <?php $ordner="../ANWENDDateien/thimg/"; $typen= array("gif","jpg","png"); $verzeichnis = opendir($ordner); $bilder = array(); while($datei = readdir($verzeichnis)) { $datei_endung = substr( strrchr($datei,".") ,1); if(in_array($datei_endung, $typen)) { $bilder[] = $datei; } } closedir($verzeichnis); srand ((double) microtime() * 10000000); $key = array_rand($bilder); echo '<img style="width:20%; height:auto" src="'.$ordner."/".$bilder[$key].'" alt=”Beschreibung der Bilder">'; ?> </body> </html> |
Kontakt Datenschutz Impressum |
|