Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> Generator miniaturek z obsługą cache
nexis
post
Post #1





Grupa: Zarejestrowani
Postów: 1 012
Pomógł: 109
Dołączył: 26.09.2003
Skąd: nexis.pl

Ostrzeżenie: (0%)
-----


Wiecie może czemu ten kod za pierwszym przebiegiem (czyli kiedy pliku nie ma na lokalnym serwerze) robi wszystkie operacje prawidłowo, ale nie wyświetla samej miniaturki?

  1. <?php
  2. $url = 'http://i-serwis2.action.pl/';
  3. $filename = 'Pictures/KOM/KOH/KOMAAAKOH0397/1.jpg';
  4. $width = 480;
  5. $height  = 480;
  6.  
  7. header('Content-type: image/jpeg');
  8.  
  9. if (file_exists($filename))
  10. {
  11. $source = imagecreatefromjpeg($filename);
  12. imagejpeg($source, null, 10);
  13. } else {
  14. $dir = '/';
  15. foreach (array_slice(explode('/', $filename), 0, -1) as $value)
  16. {
  17. mkdir($dir.$value);
  18. $dir .= $value . '/';
  19. }
  20.  
  21. list($fwidth, $fheight) = getimagesize($url.$filename);
  22. if ($width/$height > $fwidth/$fheight)
  23. {
  24. $newwidth = ceil($fwidth/($fheight/$height));
  25. $newheight = $height;
  26. } else {
  27. $newwidth = $width;
  28. $newheight = ceil($fheight/($fwidth/$width));
  29. }
  30. $thumb = imagecreatetruecolor($newwidth, $newheight);
  31. $source = imagecreatefromjpeg($url.$filename);
  32. imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $fwidth, $fheight);
  33. imagejpeg($thumb, $filename, 100);
  34. }
  35. ?>


Miniaturka ładowana z dysku lokalnego ma celowo ustawioną jakość na 10% żeby było wiadomo czy jest to miniaturka lokalna czy zdalna. winksmiley.jpg

//EDIT

Dałem po prostu na końcu
  1. <?php
  2. ...
  3. header('location:' . $_SERVER['PHP_SELF']);
  4. }
  5. ?>
. smile.gif

Ten post edytował nexis 28.10.2007, 15:20:23


--------------------
Zend Certified Engineer

Kliknij POMÓGŁ jeśli moja odpowiedź okazała się użyteczna!
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 20.08.2025 - 07:50