Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL][PHP]: imagesx() expects parameter 1 to be resource
habuuu
post 10.04.2013, 14:39:54
Post #1





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 24.05.2012

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


Witam mam problem z tworzeniem miniaturki do zdjęcia wyskakują mi następujące błędy

Notice: Undefined variable: img

Warning: imagesx() expects parameter 1 to be resource, null given

Warning: imagesy() expects parameter 1 to be resource, null given
  1. <?php
  2.  
  3.  
  4. function findExtension ($filename)
  5. {
  6. $filename = strtolower($filename) ;
  7. $exts = explode("[/\\.]", $filename) ;
  8. $n = count($exts)-1;
  9. $exts = $exts[$n];
  10. return $exts;
  11. }
  12.  
  13.  
  14. function imagecreatefromunknown($path) {
  15.  
  16. $ext = findExtension($path);
  17.  
  18. switch ($ext) {
  19. case "jpg":
  20. $img = imagecreatefromjpeg($path);
  21. break;
  22. case "gif":
  23. $img = imagecreatefromgif($path);
  24. break;
  25. case "png":
  26. $img = imagecreatefrompng($path);
  27. break;
  28. }
  29.  
  30. return $img;
  31. }
  32.  
  33.  
  34.  
  35. $max = 3;
  36. $total = 0;
  37.  
  38.  
  39. if (isset($_POST["tags1"])) {
  40.  
  41. $date = date("d-m-y");
  42. $lastaccess = date("y-m-d");
  43. $ip= $_SERVER['REMOTE_ADDR'];
  44.  
  45.  
  46. for ($i=1; $i < ($max+1); $i++)
  47. {
  48. if (trim($_FILES["image" . $i]["name"]) != "") {
  49.  
  50. $total = $total + 1;
  51. if ( (trim($_POST["tags" . $i]) != "") ) {
  52.  
  53. $tags = htmlspecialchars(trim($_POST["tags" . $i]));
  54.  
  55. $name = "image" . $i;
  56.  
  57.  
  58. if (( ($_FILES[$name]["type"] == "image/gif")
  59. || ($_FILES[$name]["type"] == "image/jpeg")
  60. || ($_FILES[$name]["type"] == "image/pjpeg")
  61. || ($_FILES[$name]["type"] == "image/x-png")
  62. || ($_FILES[$name]["type"] == "image/bmp")
  63. || ($_FILES[$name]["type"] == "image/png")))
  64. {
  65.  
  66. $size = intval(($_FILES[$name]["size"] / 1024) / 1024);
  67.  
  68. if ($session == true)
  69. $limit = $maxsizemember;
  70. else
  71. $limit = $maxsizeguest;
  72.  
  73. if ($size > $limit)
  74. die ("Przepraszamy! Rozmiar zdjęcia przekracza limit MB.");
  75.  
  76.  
  77. if ($_FILES[$name]["error"] > 0) {
  78. die("Error: " . $_FILES[$name]["error"]);
  79. }
  80. else {
  81. $n = $_FILES[$name]["name"];
  82. $rndName = md5($n . date("d-m-y") . time()) . "." . findExtension($n);
  83. $uploadPath = "pictures/" . $rndName;
  84. $tempPath = $_FILES[$name]["tmp_name"];
  85. move_uploaded_file($tempPath, $uploadPath);
  86. }
  87.  
  88. }
  89. else
  90. die("Sorry ! \"{$_FILES[$name]["name"]}\" nie prawidłowy format zdjęcia.");
  91.  
  92.  
  93. $imagePath = $uploadPath;
  94.  
  95.  
  96.  
  97. $img = imagecreatefromunknown($imagePath);
  98.  
  99. $mainWidth = imagesx($img);
  100. $mainHeight = imagesy($img);
  101.  
  102. if (($mainWidth > 150) && ($mainWidth < 2000) && ($mainHeight < 1600))
  103. {
  104.  
  105. $a = ($mainWidth >= $mainHeight) ? $mainWidth : $mainHeight;
  106.  
  107. $div = $a / 150;
  108. $thumbWidth = intval($mainWidth / $div);
  109. $thumbHeight = intval($mainHeight / $div);
  110.  
  111.  
  112. $myThumb = imagecreatetruecolor($thumbWidth, $thumbHeight);
  113. imagecopyresampled($myThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $mainWidth, $mainHeight);
  114. $thumbPath = "thumbnails/" . basename($imagePath);
  115. imagejpeg($myThumb, $thumbPath);
  116.  
  117.  
  118.  
  119.  
  120.  
  121. if (($type == "public") && ($watermark == "true")) {
  122. $imgMark = imagecreatefromgif("watermark.gif");
  123.  
  124. $dX = $mainWidth - imagesx($imgMark);
  125. $dY = $mainHeight - imagesy($imgMark);
  126. imagecopymerge($img, $imgMark, $dX, $dY, 0, 0, imagesx($imgMark), imagesy($imgMark), 40);
  127.  
  128. $ext = findExtension($imagePath);
  129.  
  130. switch ($ext) {
  131. case "jpg":
  132. imagejpeg($img, $imagePath); break;
  133. case "png":
  134. imagepng($img, $imagePath); break;
  135. }
  136. }
  137.  
  138.  
  139.  
  140. $details = intval(filesize($imagePath) / 1024) . " kb (" . $mainWidth . " x " . $mainHeight . ")" ;
  141. $id = md5($thumbPath . date("d-m-y") . time());
  142. ?>
Go to the top of the page
+Quote Post

Posty w temacie


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 Wersja Lo-Fi Aktualny czas: 14.08.2025 - 20:56