Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: switch + png błąd tworzy uszkodzony plik
Forum PHP.pl > Forum > PHP
sigal2006
modyfikowałem skrypt scałowania fotografii i mam problem wszystko działa oki tworzy miniaturkę w jpg i gif ale jak zaczyna z png to tworzy się plik uszkodzony.

Jakieś pomysły

  1. <?
  2. $nazwa_sesji='pad_ogloszenia';
  3.  
  4. function connection() {
  5. global $conn;
  6.  
  7. include('config.php');
  8.  
  9. if ($conn)
  10. return $conn;
  11. else {
  12. $conn = mysql_connect ($mysql_host, $mysql_base, $mysql_pass);
  13. if (!$conn || !mysql_select_db ($mysql_users, $conn))
  14. return 0;
  15. else
  16. return $conn;
  17. }
  18. }
  19.  
  20. function query ($sqlquery) {
  21. if (!($conn = connection ()))
  22. return 0;
  23. else {
  24. $result = mysql_query ($sqlquery, $conn);
  25. if (!$result)
  26. echo "Bł‘d w zapytaniu!";
  27. else
  28. return $result;
  29. }
  30. }
  31.  
  32. function next_record ($result) {
  33. $ans = mysql_fetch_row ($result);
  34. return $ans;
  35. }
  36.  
  37. function records_qty ($result) {
  38. return (mysql_num_rows ($result));
  39. }
  40.  
  41. function check ($sql_zapytanie) {
  42. $sql_result = query ($sql_zapytanie);
  43. return records_qty ($sql_result);
  44. }
  45.  
  46. function sql_select ($sql_zapytanie) {
  47. $sql_result = query ($sql_zapytanie);
  48. $result[0][0] = records_qty ($sql_result);
  49.  
  50. for ($a = 1; $a <= $result[0][0]; $a++) {
  51. $ans = next_record ($sql_result);
  52. $result [$a] = $ans;
  53. }
  54. return ($result);
  55. }
  56.  
  57. function sql_update ($sql_zapytanie) {
  58. $sql_result = query ($sql_zapytanie);
  59. }
  60.  
  61. function sql_delete ($sql_zapytanie) {
  62. $sql_result = query ($sql_zapytanie);
  63. }
  64.  
  65. function sql_insert ($sql_zapytanie) {
  66. $sql_result = query ($sql_zapytanie);
  67. }
  68.  
  69. function idtodate($id){
  70. $rok=substr($id,0,4);
  71. $miesiac=substr($id,4,-8);
  72. $dzien=substr($id,6,-6);
  73. $data="$dzien-$miesiac-$rok";
  74. return $data;
  75. }
  76.  
  77. function domyslny_plik($d_plik){
  78. if ($d_plik == 0)
  79. $wyjscie="ogloszenia.php";
  80. else
  81. $wyjscie="oczekujace.php";
  82. return $wyjscie;
  83. }
  84.  
  85. function zdjecia($zdjecie, $roz_obrazka, $ogl_id, $i){
  86. move_uploaded_file($zdjecie, "o_images/".$ogl_id."_".$i.$roz_obrazka);
  87.  
  88. switch ($roz_obrazka)
  89. {
  90. case '.gif':
  91. $source2 = imagecreatefromgif("../o_images/".$ogl_id."_".$i.".gif");
  92. break;
  93. case '.jpg':
  94. $source2 = imagecreatefromjpeg("../o_images/".$ogl_id."_".$i.".jpg");
  95. break;
  96. case '.jpeg':
  97. $source2 = imagecreatefromjpeg("../o_images/".$ogl_id."_".$i.".jpg");
  98. break;
  99. case '.png':
  100. $source2 = imagecreatefrompng("../o_images/".$ogl_id."_".$i.".png");
  101. break;
  102. }
  103.  
  104. if(imagesy($source2)>150){
  105. $new_height2 = floor(imagesy($source2)*(150/imagesx($source2)));
  106. $new_width2 = 150;
  107. }
  108. else{
  109. $new_width2 = imagesx($source2);
  110. $new_height2 = imagesy($source2);
  111. }
  112. $dest2 = imagecreatetruecolor($new_width2,$new_height2);
  113. imagecopyresampled($dest2,$source2,0,0,0,0,$new_width2,$new_height2,imagesx($source2),imagesy($source2));
  114. switch ($roz_obrazka)
  115. {
  116. case '.gif':
  117. imagegif($dest2,"../o_images/min_".$ogl_id."_".$i.".gif",50);
  118. break;
  119. case '.jpg':
  120. imagejpeg($dest2,"../o_images/min_".$ogl_id."_".$i.".jpg",50);
  121. break;
  122. case '.jpeg':
  123. imagejpeg($dest2,"../o_images/min_".$ogl_id."_".$i.".jpg",50);
  124. break;
  125. case '.png':
  126. imagepng($dest2,"../o_images/min_".$ogl_id."_".$i.".png",50);
  127. break;
  128. }
  129. imagedestroy($source2);
  130. imagedestroy($dest2);
  131.  
  132. switch ($roz_obrazka)
  133. {
  134. case '.gif':
  135. $source = imagecreatefromgif("../o_images/".$ogl_id."_".$i.".gif");
  136. break;
  137. case '.jpg':
  138. $source = imagecreatefromjpeg("../o_images/".$ogl_id."_".$i.".jpg");
  139. break;
  140. case '.jpeg':
  141. $source = imagecreatefromjpeg("../o_images/".$ogl_id."_".$i.".jpg");
  142. break;
  143. case '.png':
  144. $source = imagecreatefrompng("../o_images/".$ogl_id."_".$i.".png");
  145. break;
  146. }
  147.  
  148. if(imagesy($source)>400){
  149. $new_height = 400;
  150. $new_width = floor(imagesx($source)*(400/imagesy($source)));
  151. }
  152. else{
  153. $new_width = imagesx($source);
  154. $new_height = imagesy($source);
  155. }
  156. $dest = imagecreatetruecolor($new_width,$new_height);
  157. imagecopyresampled($dest,$source,0,0,0,0,$new_width,$new_height,imagesx($source),imagesy($source));
  158. switch ($roz_obrazka)
  159. {
  160. case '.gif':
  161. imagegif($dest,"../o_images/".$ogl_id."_".$i.".gif",50);
  162. break;
  163. case '.jpg':
  164. imagejpeg($dest,"../o_images/".$ogl_id."_".$i.".jpg",50);
  165. break;
  166. case '.jpeg':
  167. imagejpeg($dest,"../o_images/".$ogl_id."_".$i.".jpg",50);
  168. break;
  169. case '.png':
  170. imagepng($dest,"../o_images/".$ogl_id."_".$i.".png",50);
  171. break;
  172. }
  173. imagedestroy($source);
  174. imagedestroy($dest);
  175. }
  176.  
  177. function zdjecia_user($zdjecie, $roz_obrazka, $ogl_id, $i){
  178. move_uploaded_file($zdjecie, "o_images/".$ogl_id."_".$i.$roz_obrazka);
  179.  
  180. switch ($roz_obrazka)
  181. {
  182. case '.gif':
  183. $source2 = imagecreatefromgif("o_images/".$ogl_id."_".$i.".gif");
  184. break;
  185. case '.jpg':
  186. $source2 = imagecreatefromjpeg("o_images/".$ogl_id."_".$i.".jpg");
  187. break;
  188. case '.jpeg':
  189. $source2 = imagecreatefromjpeg("o_images/".$ogl_id."_".$i.".jpg");
  190. break;
  191. case '.png':
  192. $source2 = imagecreatefrompng("o_images/".$ogl_id."_".$i.".png");
  193. break;
  194. }
  195.  
  196. if(imagesy($source2)>150){
  197. $new_height2 = floor(imagesy($source2)*(150/imagesx($source2)));
  198. $new_width2 = 150;
  199. }
  200. else{
  201. $new_width2 = imagesx($source2);
  202. $new_height2 = imagesy($source2);
  203. }
  204. $dest2 = imagecreatetruecolor($new_width2,$new_height2);
  205. imagecopyresampled($dest2,$source2,0,0,0,0,$new_width2,$new_height2,imagesx($source2),imagesy($source2));
  206. switch ($roz_obrazka)
  207. {
  208. case '.gif':
  209. //touch("o_images/min_".$ogl_id."_".$i.".gif");
  210. imagegif($dest2,"o_images/min_".$ogl_id."_".$i.".gif",50);
  211. break;
  212. case '.jpg':
  213. //touch("o_images/min_".$ogl_id."_".$i.".jpg");
  214. imagejpeg($dest2,"o_images/min_".$ogl_id."_".$i.".jpg",50);
  215. break;
  216. case '.jpeg':
  217. //touch("o_images/min_".$ogl_id."_".$i.".jpg");
  218. imagejpeg($dest2,"o_images/min_".$ogl_id."_".$i.".jpg",50);
  219. break;
  220. case '.png':
  221. //touch("o_images/min_".$ogl_id."_".$i.".png");
  222. imagepng($dest2,"o_images/min_".$ogl_id."_".$i.".png",50);
  223. break;
  224. }
  225. imagedestroy($source2);
  226. imagedestroy($dest2);
  227.  
  228. switch ($roz_obrazka)
  229. {
  230. case '.gif':
  231. $source = imagecreatefromgif("o_images/".$ogl_id."_".$i.".gif");
  232. break;
  233. case '.jpg':
  234. $source = imagecreatefromjpeg("o_images/".$ogl_id."_".$i.".jpg");
  235. break;
  236. case '.jpeg':
  237. $source = imagecreatefromjpeg("o_images/".$ogl_id."_".$i.".jpg");
  238. break;
  239. case '.png':
  240. $source = imagecreatefrompng("o_images/".$ogl_id."_".$i.".png");
  241. break;
  242. }
  243.  
  244. if(imagesy($source)>400){
  245. $new_height = 400;
  246. $new_width = floor(imagesx($source)*(400/imagesy($source)));
  247. }
  248. else{
  249. $new_width = imagesx($source);
  250. $new_height = imagesy($source);
  251. }
  252. $dest = imagecreatetruecolor($new_width,$new_height);
  253. imagecopyresampled($dest,$source,0,0,0,0,$new_width,$new_height,imagesx($source),imagesy($source));
  254. switch ($roz_obrazka)
  255. {
  256. case '.gif':
  257. //touch("o_images/".$ogl_id."_".$i.".gif");
  258. imagegif($dest,"o_images/".$ogl_id."_".$i.".gif",50);
  259. break;
  260. case '.jpg':
  261. //touch("o_images/".$ogl_id."_".$i.".jpg");
  262. imagejpeg($dest,"o_images/".$ogl_id."_".$i.".jpg",50);
  263. break;
  264. case '.jpeg':
  265. //touch("o_images/".$ogl_id."_".$i.".jpg");
  266. imagejpeg($dest,"o_images/".$ogl_id."_".$i.".jpg",50);
  267. break;
  268. case '.png':
  269. //touch("o_images/".$ogl_id."_".$i.".png");
  270. imagepng($dest,"o_images/".$ogl_id."_".$i.".png",50);
  271. break;
  272. }
  273. imagedestroy($source);
  274. imagedestroy($dest);
  275. }
  276.  
  277. function tytul($tytul){
  278. $s_len=strlen($tytul);
  279. if (strlen($tytul) > 25){
  280. for ($i=0;$i<25;$i++){
  281. $new_t=$tytul[$i];
  282. echo $new_t;
  283. }
  284. echo' ...';
  285. }
  286. else
  287. echo $tytul;
  288. }
  289.  
  290. function tytul_ogl($str){
  291. $str=str_replace(" ","_",$str);
  292. $str=str_replace("Âą","a",$str);
  293. $str=str_replace("ć","c",$str);
  294. $str=str_replace("Ä™","e",$str);
  295. $str=str_replace("Ĺ‚","l",$str);
  296. $str=str_replace("Ĺ„","n",$str);
  297. $str=str_replace("Ăł","o",$str);
  298. $str=str_replace("Âś","s",$str);
  299. $str=str_replace("ĹĽ","z",$str);
  300. $str=str_replace("Ä˝","z",$str);
  301. $str=str_replace("ˇ","A",$str);
  302. $str=str_replace("Ć","C",$str);
  303. $str=str_replace("Ę","E",$str);
  304. $str=str_replace("Ł","L",$str);
  305. $str=str_replace("Ń","N",$str);
  306. $str=str_replace("Ă“","O",$str);
  307. $str=str_replace("ÂŚ","S",$str);
  308. $str=str_replace("Ĺť","Z",$str);
  309. $str=str_replace("ÂŹ","Z",$str);
  310. $str = strtolower($str);
  311. $str = preg_replace('/[^a-z0-9_]/', '', $str);
  312. return $str;
  313. }
  314. ?>
CuteOne
Takie pytanie... po co duplikujesz ten sam kod 3 razy!? Co do pytania problemem, może być ustawienie quality dla png - tu masz rozwiązanie link
erix
Poza tym, podejrzyj binarnie PNG, czy nie ma tam wrzuconych jakichś błędów z PHP.
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.