Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Zapisywanie zdjęcia
Forum PHP.pl > Forum > Przedszkole
eko_moto
Napisałem taki kod php do rysowania:

  1. <?php
  2.  
  3. $fontDir = 'fonts';
  4. $font = "MiniForma2.ttf";
  5. $length = 6;
  6. $img = imagecreate(100,25);
  7. $fontColor = imagecolorallocate($img,11,11,11);
  8. $bg = imagecolorallocate($img,240,240,240);
  9. imagefill($img,0,0,$bg);
  10.  
  11.  $string = substr(md5(uniqid(rand(1,9)))), 0, $length);
  12.  
  13.  for ($i = 0; $i < $length; $i++) {
  14. imagettftext($img, 12, rand(2,10), rand(1,5)+$i*15, 20+rand(-3,3), $fontColor, $fontDir.'/'.$font, $string{$i});
  15. }
  16.  
  17. header('Content-type: image/gif');
  18. imagegif($img);
  19.  
  20. ?>


Tutaj jest próbka wygenerowanego obrazu...


I teraz pytanie...
Czy można zapisać do pliku .gif wygenerowany obraz? Czy jest do tego jakaś konkretna funkcja?
angel2953
imagegif
tiraeth
Jako drugi parametr funkcji imagegif należy podać ścieżkę z nazwą pliku, pod którą php ma zapisać obraz.

  1. <?php
  2.  
  3. $fontDir = 'fonts';
  4. $font = "MiniForma2.ttf";
  5. $length = 6;
  6. $img = imagecreate(100,25);
  7. $fontColor = imagecolorallocate($img,11,11,11);
  8. $bg = imagecolorallocate($img,240,240,240);
  9. imagefill($img,0,0,$bg);
  10.  
  11. $string = substr(md5(uniqid(rand(1,9)))), 0, $length);
  12.  
  13. for ($i = 0; $i < $length; $i++)
  14. {
  15. imagettftext($img, 12, rand(2,10), rand(1,5)+$i*15, 20+rand(-3,3), $fontColor, $fontDir.'/'.$font, $string{$i});
  16. }
  17.  
  18. header('Content-type: image/gif');
  19. imagegif($img, "obrazek.gif");
  20.  
  21. ?>
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.