Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP] znak wodny w php
Forum PHP.pl > Forum > Przedszkole
nigraS
  1. <?php
  2. // this script creates a watermarked image from an image file - can be a .jpg .gif or .png file
  3. // where watermark.gif is a mostly transparent gif image with the watermark - goes in the same directory as this script
  4. // where this script is named watermark.php
  5. // call this script with an image tag
  6. // <img src="watermark.php?path=imagepath"> where path is a relative path such as subdirectory/image.jpg
  7. $imagesource = $_GET['path'];
  8. $filetype = substr($imagesource,strlen($imagesource)-4,4);
  9. $filetype = strtolower($filetype);
  10. if($filetype == ".gif") $image = @imagecreatefromgif($imagesource);
  11. if($filetype == ".jpg") $image = @imagecreatefromjpeg($imagesource);
  12. if($filetype == ".png") $image = @imagecreatefrompng($imagesource);
  13. if (!$image) die();
  14. $watermark = @imagecreatefromgif('watermark.gif');
  15. $imagewidth = imagesx($image);
  16. $imageheight = imagesy($image);
  17. $watermarkwidth = imagesx($watermark);
  18. $watermarkheight = imagesy($watermark);
  19. $startwidth = ((0) );
  20. $startheight = (($imageheight - $watermarkheight) );
  21. imagecopy($image, $watermark, $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight);
  22. imagejpeg($image);
  23. imagedestroy($image);
  24. imagedestroy($watermark);
  25. ?>


obrazek się nie wyswietla.
http://www.telefonyforum.pl/watermark.php?...max/foto_01.jpg

co jest nie tak?
jaslanin
wstaw na początku:

  1. header("Content-type: image/jpeg");


+++ zapomniałem że to obsługuje parę formatów, więc powinno być tak:

  1. <?php
  2. // this script creates a watermarked image from an image file - can be a .jpg .gif or .png file
  3. // where watermark.gif is a mostly transparent gif image with the watermark - goes in the same directory as this script
  4. // where this script is named watermark.php
  5. // call this script with an image tag
  6. // <img src="watermark.php?path=imagepath"> where path is a relative path such as subdirectory/image.jpg
  7. $imagesource = $_GET['path'];
  8. $filetype = substr($imagesource, strlen($imagesource) - 4, 4);
  9. $filetype = strtolower($filetype);
  10. if ($filetype == ".gif") {
  11. $image = @imagecreatefromgif($imagesource);
  12. header("Content-type: image/gif");
  13. }
  14. if ($filetype == ".jpg") {
  15. $image = @imagecreatefromjpeg($imagesource);
  16. header("Content-type: image/jpeg");
  17. }
  18. if ($filetype == ".png") {
  19. $image = @imagecreatefrompng($imagesource);
  20. header("Content-type: image/png");
  21. }
  22. if (!$image)
  23. die();
  24. $watermark = @imagecreatefromgif('watermark.gif');
  25. $imagewidth = imagesx($image);
  26. $imageheight = imagesy($image);
  27. $watermarkwidth = imagesx($watermark);
  28. $watermarkheight = imagesy($watermark);
  29. $startwidth = ((0) );
  30. $startheight = (($imageheight - $watermarkheight) );
  31. imagecopy($image, $watermark, $startwidth, $startheight, 0, 0, $watermarkwidth, $watermarkheight);
  32. imagejpeg($image);
  33. imagedestroy($image);
  34. imagedestroy($watermark);
  35. ?>
nigraS
super, dzięki!
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.