Zufallsbilder


  • XtreamAlone
  • 1968 Aufrufe 13 Antworten

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Zufallsbilder

    Hi Leute
    Vielleicht klingt das alles ein bischen "noobisch" in euren Augen, aber ich habe eine Frage zu HTML.

    Also ich wollte ein Textfenster auf eine Seite einbauen, so eine Art Shoutbox, in der zufallsgeneriert Bilder dargestellt werden, die ich vorher hochgeladen habe.

    Also die Bilder von meinem Space da quasi zufallsgeneriert in so ner kleinen Box am Rand erscheinen.

    Wie mach ich das?

    Mit nem einfachen <href.... Code? oder wie jetzt?

    Bitte helft mir!


    Greetz Ingo
    zur Zeit wenig aktiv!
    [SIZE="1"][COLOR="RoyalBlue"]gesucht werden: Upper (ab 6Mbit), Scanner (Mssql/PMA/Mysql), Coder (C++/VB)[/color]
    [/SIZE]
  • nein, mit html ist dies nicht möglich!
    Dafür benötigst du php, denn mit html kannst du nur statische seiten machen, also Seiten die sich nicht verändern.

    mfg -HG-

    EDIT:

    PHP-Quellcode

    1. <?php
    2. $zufall = rand(1,100); // erzeug Zufallszahl zwischen 1 und 100
    3. $pic = "Bild".$zufall.".jpg"; // setzt den Name des Bildes zusammen, also "Bild1",..,"Bild23",...,"Bild100"
    4. echo "<img src=$pic alt=$pic border=0>"; // Bild einfügen
    5. ?>

    so gehts...
  • PHP-Quellcode

    1. <?php
    2. /*
    3. AUTOMATIC IMAGE ROTATOR
    4. Version 2.2 - December 4, 2003
    5. Copyright (c) 2002-2003 Dan P. Benjamin, Automatic, Ltd.
    6. All Rights Reserved.
    7. [url]http://www.hiveware.com/imagerotator.php[/url]
    8. [url]http://www.automaticlabs.com/[/url]
    9. DISCLAIMER
    10. Automatic, Ltd. makes no representations or warranties about
    11. the suitability of the software, either express or
    12. implied, including but not limited to the implied
    13. warranties of merchantability, fitness for a particular
    14. purpose, or non-infringement. Dan P. Benjamin and Automatic, Ltd.
    15. shall not be liable for any damages suffered by licensee
    16. as a result of using, modifying or distributing this
    17. software or its derivatives.
    18. ABOUT
    19. This PHP script will randomly select an image file from a
    20. folder of images on your webserver. You can then link to it
    21. as you would any standard image file and you'll see a random
    22. image each time you reload.
    23. When you want to add or remove images from the rotation-pool,
    24. just add or remove them from the image rotation folder.
    25. VERSION CHANGES
    26. Version 1.0
    27. - Release version
    28. Version 1.5
    29. - Tweaked a few boring bugs
    30. Version 2.0
    31. - Complete rewrite from the ground-up
    32. - Made it clearer where to make modifications
    33. - Made it easier to specify/change the rotation-folder
    34. - Made it easier to specify/change supported image types
    35. - Wrote better instructions and info (you're them reading now)
    36. - Significant speed improvements
    37. - More error checking
    38. - Cleaner code (albeit more PHP-specific)
    39. - Better/faster random number generation and file-type parsing
    40. - Added a feature where the image to display can be specified
    41. - Added a cool feature where, if an error occurs (such as no
    42. images being found in the specified folder) *and* you're
    43. lucky enough to have the GD libraries compiled into PHP on
    44. your webserver, we generate a replacement "error image" on
    45. the fly.
    46. Version 2.1
    47. - Updated a potential security flaw when value-matching
    48. filenames
    49. Version 2.2
    50. - Updated a few more potential security issues
    51. - Optimized the code a bit.
    52. - Expanded the doc for adding new mime/image types.
    53. Thanks to faithful ALA reader Justin Greer for
    54. lots of good tips and solid code contribution!
    55. INSTRUCTIONS
    56. 1. Modify the $folder setting in the configuration section below.
    57. 2. Add image types if needed (most users can ignore that part).
    58. 3. Upload this file (rotate.php) to your webserver. I recommend
    59. uploading it to the same folder as your images.
    60. 4. Link to the file as you would any normal image file, like this:
    61. <img src="http://example.com/rotate.php">
    62. 5. You can also specify the image to display like this:
    63. <img src="http://example.com/rotate.php?img=gorilla.jpg">
    64. This would specify that an image named "gorilla.jpg" located
    65. in the image-rotation folder should be displayed.
    66. That's it, you're done.
    67. */
    68. /* ------------------------- CONFIGURATION -----------------------
    69. Set $folder to the full path to the location of your images.
    70. For example: $folder = '/user/me/example.com/images/';
    71. If the rotate.php file will be in the same folder as your
    72. images then you should leave it set to $folder = '.';
    73. */
    74. $folder = '.';
    75. /*
    76. Most users can safely ignore this part. If you're a programmer,
    77. keep reading, if not, you're done. Go get some coffee.
    78. If you'd like to enable additional image types other than
    79. gif, jpg, and png, add a duplicate line to the section below
    80. for the new image type.
    81. Add the new file-type, single-quoted, inside brackets.
    82. Add the mime-type to be sent to the browser, also single-quoted,
    83. after the equal sign.
    84. For example:
    85. PDF Files:
    86. $extList['pdf'] = 'application/pdf';
    87. CSS Files:
    88. $extList['css'] = 'text/css';
    89. You can even serve up random HTML files:
    90. $extList['html'] = 'text/html';
    91. $extList['htm'] = 'text/html';
    92. Just be sure your mime-type definition is correct!
    93. */
    94. $extList = array();
    95. $extList['gif'] = 'image/gif';
    96. $extList['jpg'] = 'image/jpeg';
    97. $extList['jpeg'] = 'image/jpeg';
    98. $extList['png'] = 'image/png';
    99. // You don't need to edit anything after this point.
    100. // --------------------- END CONFIGURATION -----------------------
    101. $img = null;
    102. if (substr($folder,-1) != '/') {
    103. $folder = $folder.'/';
    104. }
    105. if (isset($_GET['img'])) {
    106. $imageInfo = pathinfo($_GET['img']);
    107. if (
    108. isset( $extList[ strtolower( $imageInfo['extension'] ) ] ) &&
    109. file_exists( $folder.$imageInfo['basename'] )
    110. ) {
    111. $img = $folder.$imageInfo['basename'];
    112. }
    113. } else {
    114. $fileList = array();
    115. $handle = opendir($folder);
    116. while ( false !== ( $file = readdir($handle) ) ) {
    117. $file_info = pathinfo($file);
    118. if (
    119. isset( $extList[ strtolower( $file_info['extension'] ) ] )
    120. ) {
    121. $fileList[] = $file;
    122. }
    123. }
    124. closedir($handle);
    125. if (count($fileList) > 0) {
    126. $imageNumber = time() % count($fileList);
    127. $img = $folder.$fileList[$imageNumber];
    128. }
    129. }
    130. if ($img!=null) {
    131. $imageInfo = pathinfo($img);
    132. $contentType = 'Content-type: '.$extList[ $imageInfo['extension'] ];
    133. header ($contentType);
    134. readfile($img);
    135. } else {
    136. if ( function_exists('imagecreate') ) {
    137. header ("Content-type: image/png");
    138. $im = @imagecreate (100, 100)
    139. or die ("Cannot initialize new GD image stream");
    140. $background_color = imagecolorallocate ($im, 255, 255, 255);
    141. $text_color = imagecolorallocate ($im, 0,0,0);
    142. imagestring ($im, 2, 5, 5, "IMAGE ERROR", $text_color);
    143. imagepng ($im);
    144. imagedestroy($im);
    145. }
    146. }
    147. ?>
    Alles anzeigen
  • Dann würde ich sagen ist PHP besser, da ich mit Javascript nicht klarkomme.

    -HG- hat nen kurzen Code geschrieben, Ding nen langen, welchen muss ich denn jetzt nehmen?

    Greetz Ingo
    zur Zeit wenig aktiv!
    [SIZE="1"][COLOR="RoyalBlue"]gesucht werden: Upper (ab 6Mbit), Scanner (Mssql/PMA/Mysql), Coder (C++/VB)[/color]
    [/SIZE]
  • Mit dem grossen Code schiesst du mit Kanonen auf Spatzen.

    Der benutzt noch die GD-Library (die auch nicht überall installiert ist) um Bilder zu erzeugen, absolut unnötiger Rechenaufwand für deine "kleine" Aufgabe...

    -purx

    PS: Bei der "kurzen" Version musst du die Bilder entsprechend benennen, also von Bild1.jpg bis BildXXX.jpg. Auch der Datentyp ist realtiv fix, man könnte da noch ne schönere Lösung basteln, dass er einfach alle Files in einem bestimmten Order nimmt und diese dann per Zufall anzeigt.
  • purx schrieb:



    PS: Bei der "kurzen" Version musst du die Bilder entsprechend benennen, also von Bild1.jpg bis BildXXX.jpg. Auch der Datentyp ist realtiv fix, man könnte da noch ne schönere Lösung basteln, dass er einfach alle Files in einem bestimmten Order nimmt und diese dann per Zufall anzeigt.



    Tja das macht mein Code, der funktioniert einwandfrei.
  • Ding schrieb:

    Tja das macht mein Code, der funktioniert einwandfrei.


    Ja für die Luxus-Lösung müsste man deinen Code kürzen, sprich um unnötigen und rechen- bzw. speicherintensiven Code erleichtern.
    Falls das gewünscht ist, kann ich das gerne mal machen.

    Mein Post war kein Angriff auf deine Lösung, nicht das du das in den falschen Hals kriegst...
    [SIZE=1]"There's no right, there's no wrong, there's only popular opinion." Jeffrey Goines (Brad Pitt) in Twelve Monkeys[/SIZE]

    [SIZE=1]$ killall chico[/SIZE]
  • euskirchenruler schrieb:

    also ich hab den kurzen code ( von -HG- ) benutzt und keine Probleme damit gehabt.

    Einwandfrei! :)

    Vielen lieben Dank nochmal



    kann man sich das auch einmal in aktion anschauen ???
    würd gern mal sehen wies aussieht ...
    suche nämlich auch sowas in der richtung