login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > PHP > GD library > Thumbnails on the fly

Thumbnails on the fly

Auteur: michielvsb - 15 augustus 2006 - 10:43 - Gekeurd door: Thomas - Hits: 6031 - Aantal punten: (0 stemmen)



Je zet dit script in hetzelfde mapje als je foto's, en je doet <image src=[naam_van_het_script].php?bestand=[naam_van_de_afbeelding]>

Het originele script komt van phphulp.nl, maar ik heb alles op orde gezet, en de comments toegevoegd.

Code:
  1. <?php
  2. $sImage = $_GET['bestand']; // Haal het bestand uit de header
  3. $iImageMaxWidth = "120"; // De maximum hoogte van de afbeelding
  4. $iImageMaxHeight = "90"; // De maximum breedte van de afbeelding
  5. $aImageData = getimagesize($bestand); // Zoek de huidige breedte en hoogte van de afbeelding op
  6. $iImageWidth = $aImageData[0]; // Haal de huidige breedte uit de array
  7. $iImageHeight = $aImageData[1]; // Haal de huidige hoogte uit de array
  8.  
  9. if ($iImageHeight > $iImageMaxWith || $iImageHeight > $iImageMaxHeight) // Kijk of de opgegeven afmetingen kleiner zijn dan de huidige
  10. {
  11. if ($iImageWidth / $iImageHeight > $iImageMaxWidth / $iImageMaxHeight) // Kijk of afbeelding te groot is
  12. {
  13. $iImageNewWidth = $iImageMaxWidth; // Verhoudingen voor breedte bepalen
  14. $iImageNewHeight = round ($iImageHeight / ($iImageWidth / $iImageMaxWidth)); // Verhoudingen voor hoogte bepalen
  15. }
  16. else
  17. {
  18. $iImageNewHeight = $iImageMaxHeight; // Verhoudingen voor hoogte bepalen
  19. $iImageNewWidth = round($iImageWidth / ($iImageHeight / $iImageMaxHeight)); // Verhoudingen bepalen voor breedte
  20. }
  21. }
  22. else // Als de afbeelding precies groot genoeg is
  23. {
  24. $iImageNewHeight = $iImageMaxHeight;
  25. $iImageNewWidth = $iImageMaxWidth;
  26. }
  27. $fImage = @imagecreatefromjpeg($bestand); // Vanuit vroegere bestand werken
  28. $fImageTemp = imagecreatetruecolor($iImageNewWidth, $iImageNewHeight);
  29. imagecopyresized($fImageTemp, $fImage, 0, 0, 0, 0, $iImageNewWidth, $iImageNewHeight, $iImageWidth, $iImageHeight); // Verkleinen
  30. imagedestroy($fImage);
  31. header("Content-type: image/jpeg"); // Header voor jpeg afbeeldingen doorsturen
  32. imagejpeg($fImageTemp, "", 75); // Uiteindelijke verkleinde afbeelding terugsturen
  33. ?>
Download code! Download code (.txt)

 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Lees de reacties (6)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.025s