Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Nie działa scrypt php..., Dlaczego?
PcPablo
post
Post #1





Grupa: Zarejestrowani
Postów: 60
Pomógł: 0
Dołączył: 20.10.2002
Skąd: Kielce

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


Mam problem ze scryptem newsowym na stronie www.camelot.slonet.one.pl

Mianowicnie nie działa scrypt pomniejszający obrazki za pomocą GD2.
Admin serwera mówi, że w innych scryptach GD2 działa poprawnie, tylko jest jakiś bug w tych newsach.

Przesyłam kod scryptu zmniejszającego obrazki za pomocą GD2:

  1. <?php
  2. /*
  3. ================================================================================
  4. ============
  5. Script Name: thumbnail.php
  6. Version: 1.1
  7. Author: Ian Anderson
  8. Date: November 2002
  9. Acknowledge: Teekai - [url=http://www.teekai.info/v8/home.php]http://www.teekai.info/v8/home.php[/url] (see the original script at
  10. [url=http://www.hotscripts.com/Detailed/18727.html]http://www.hotscripts.com/Detailed/18727.html[/url] on which this script is based).
  11.  
  12. This script is a self-contained Thumbnail Image Generator. It should be called as follows ...
  13.  
  14. <img src="/path/to/thumbnail.php?gd=N&src=/path/to/image.EXT&maxw=NNN" />
  15.  
  16. where N = the GD library version (supported values are 1 and 2)
  17. EXT = the file extension of the image file
  18. (supported values are gif (if gd = 2), jpg and png)
  19. NNN = the desired maximum width of the thumbnail
  20.  
  21. If the actual image is narrower than the desired maximum width then the original image size
  22. is used for the thumbnail copy.
  23.  
  24. This script checks for the following errors and generates an error JPEG image accordingly ...
  25.  
  26. GD version selected neither 1 nor 2;
  27. Image create functions not supported;
  28. Image file not found at the selected location;
  29. GD version 2 functions not supported on the running version of php.
  30.  
  31. This script is available for use as freeware subject to the retention of the preceding
  32. information and acknowledgements in any copy or modification that is made to this code.
  33. ================================================================================
  34. ============
  35. */
  36.  
  37. function ErrorImage ($text) {
  38. global $maxw;
  39. $len = strlen ($text);
  40. if ($maxw < 154) $errw = 154;
  41. $errh = 30;
  42. $chrlen = intval (5.9 * $len);
  43. $offset = intval (($errw - $chrlen) / 2);
  44. $im = imagecreate ($errw, $errh); /* Create a blank image */
  45. $bgc = imagecolorallocate ($im, 153, 63, 63);
  46. $tc = imagecolorallocate ($im, 255, 255, 255);
  47. imagefilledrectangle ($im, 0, 0, $errw, $errh, $bgc);
  48. imagestring ($im, 2, $offset, 7, $text, $tc);
  49. header ("Content-type: image/jpeg");
  50. imagejpeg ($im);
  51. imagedestroy ($im);
  52. exit;
  53. }
  54.  
  55. function thumbnail ($gdver, $src, $maxw=190) {
  56.  
  57. $gdarr = array (1,2);
  58. for ($i=0; $i<count($gdarr); $i++) {
  59. if ($gdver != $gdarr[$i]) $test.="|";
  60. }
  61. $exp = explode ("|", $test);
  62. if (count ($exp) == 3) {
  63. ErrorImage ("Incorrect GD version!");
  64. }
  65.  
  66. if (!function_exists ("imagecreate") || !function_exists ("imagecreatetruecolor")) {
  67. ErrorImage ("No image create functions!");
  68. }
  69.  
  70. $size = @getimagesize ($src);
  71. if (!$size) {
  72. ErrorImage ("Image File Not Found!");
  73. } else {
  74.  
  75. if ($size[0] > $maxw) {
  76. $newx = intval ($maxw);
  77. $newy = intval ($size[1] * ($maxw / $size[0]));
  78. } else {
  79. $newx = $size[0];
  80. $newy = $size[1];
  81. }
  82.  
  83. if ($gdver == 1) {
  84. $destimg = imagecreate ($newx, $newy );
  85. } else {
  86. $destimg = @imagecreatetruecolor ($newx, $newy ) or die (ErrorImage ("Cannot use GD2 here!"));
  87. }
  88.  
  89. if ($size[2] == 1) {
  90. if (!function_exists ("imagecreatefromgif")) {
  91. ErrorImage ("Cannot Handle GIF Format!");
  92. } else {
  93. $sourceimg = imagecreatefromgif ($src);
  94.  
  95. if ($gdver == 1)
  96. imagecopyresized ($destimg, $sourceimg, 0,0,0,0, $newx, $newy, $size[0], $size[1]);
  97. else
  98. @imagecopyresampled ($destimg, $sourceimg, 0,0,0,0, $newx, $newy, $size[0], $size[1]) or die (ErrorImage ("Cannot use GD2 here!"));
  99.  
  100. header ("content-type: image/gif");
  101. imagegif ($destimg);
  102. }
  103. }
  104. elseif ($size[2]==2) {
  105. $sourceimg = imagecreatefromjpeg ($src);
  106.  
  107. if ($gdver == 1)
  108. imagecopyresized ($destimg, $sourceimg, 0,0,0,0, $newx, $newy, $size[0], $size[1]);
  109. else
  110. @imagecopyresampled ($destimg, $sourceimg, 0,0,0,0, $newx, $newy, $size[0], $size[1]) or die (ErrorImage ("Cannot use GD2 here!"));
  111.  
  112. header ("content-type: image/jpeg");
  113. imagejpeg ($destimg);
  114. }
  115. elseif ($size[2] == 3) {
  116. $sourceimg = imagecreatefrompng ($src);
  117.  
  118. if ($gdver == 1)
  119. imagecopyresized ($destimg, $sourceimg, 0,0,0,0, $newx, $newy, $size[0], $size[1]);
  120. else
  121. @imagecopyresampled ($destimg, $sourceimg, 0,0,0,0, $newx, $newy, $size[0], $size[1]) or die (ErrorImage ("Cannot use GD2 here!"));
  122.  
  123. header ("content-type: image/png");
  124. imagepng ($destimg);
  125. }
  126. else {
  127. ErrorImage ("Image Type Not Handled!");
  128. }
  129. }
  130.  
  131. imagedestroy ($destimg);
  132. imagedestroy ($sourceimg);
  133. }
  134.  
  135. thumbnail ($_GET["gd"], $_GET["src"], $_GET["maxw"]);
  136. ?>


Może znajdzie ktoś jakiś błąd w tym scrypcie.


--------------------
Respect Yourself!
Go to the top of the page
+Quote Post

Posty w temacie
- PcPablo   Nie działa scrypt php...   18.09.2004, 13:08:43
- - mpps   a jakiś error wywala?   28.09.2004, 22:12:33
- - PcPablo   Już jest wszystko Ok, dzieki.   28.09.2004, 22:19:39


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: 19.08.2025 - 12:54