Witam, borykam się z takim oto problemem. Jestem w trakcie pisania stronki mojej miejscowości w panelu administracyjnym jest dział dodawania galeri, który wyglada tak, że pewna osoba wrzuca .zip ze zdjęciami php rozpakowywuje, zapisuje, tworzy w tym folderze nowy folder o nazwie "male" i powinien każde zdjecie zmiejszyć i zapisać dodatkowo w tym folderze. Problem jest taki, ze owszem zdjecia sie zmiejszają i zapisuja ale są to czarne prostokąty..

Oto kod:
  1. $nazwa = basename($_FILES['userfile']['name']);
  2. $nazwaa = substr("$nazwa", 0, (strlen ("$nazwa") - 4));
  3. if(!mkdir("../index/foto/$nazwaa")) {
  4. echo("nie udało sie"); }
  5. else{
  6. chmod("../index/foto/$nazwaa", 0777);
  7. echo "1. Utworzono folder $nazwaa</br>";
  8. $location = "../index/foto/$nazwaa/$nazwa" ;
  9.  
  10. if (move_uploaded_file($_FILES['userfile']['tmp_name'], $location) && chmod("../index/foto/$nazwaa/$nazwa", 0777)) {
  11. echo "2 .Plik został załadowany poprawnie...$nazwa </br>";
  12. } else {
  13. echo "2 .Plik nie został załadowany..$nazwa</br>";
  14. }
  15.  
  16.  
  17. $zip = new ZipArchive;
  18. if ($zip->open("../index/foto/$nazwaa/$nazwa") !== TRUE) {
  19.  
  20. echo "3 .Powstały jakieś błędy sprawdź archiwum lub folder </br>";
  21. } else {
  22.  
  23. $zip->extractTo("../index/foto/$nazwaa/");
  24.  
  25. $zip->close();
  26. echo '3. Pliki wypakowane </br>';
  27. }
  28. unlink ("../index/foto/$nazwaa/$nazwa");
  29.  
  30. if(!mkdir("../index/foto/$nazwaa/male")) {
  31. echo("nie udało sie"); }
  32. else{
  33. chmod("../index/foto/$nazwaa/male", 0777);
  34.  
  35. $directory="../index/foto/$nazwaa";
  36. $dir = opendir("$directory");
  37. $file_list="";
  38. while($file_name=readdir($dir))
  39. {
  40. if(($file_name!=".")&&($file_name!=".."))
  41. {
  42. if (strrpos ($file_name, '.jpg') || strrpos ($file_name, '.jpeg') || strrpos ($file_name, '.JPG') || strrpos ($file_name, '.JPEG'))
  43. {
  44. include("simpleimage.php");
  45. $image = new SimpleImage();
  46. $image->load("$file_name");
  47. $image->resize(75,100);
  48. $image->save("../index/foto/$nazwaa/male/$file_name");
  49. }
  50. }
  51. }
  52. closedir($dir);
  53. echo "Gotowe:)";


simpleimage:

  1.  
  2.  
  3. class simpleimage {
  4.  
  5. var $image;
  6. var $image_type;
  7.  
  8. function load($filename) {
  9.  
  10. $this->image_type = $image_info[2];
  11. if( $this->image_type == IMAGETYPE_JPEG ) {
  12. $this->image = imagecreatefromjpeg($filename);
  13. } elseif( $this->image_type == IMAGETYPE_GIF ) {
  14. $this->image = imagecreatefromgif($filename);
  15. } elseif( $this->image_type == IMAGETYPE_PNG ) {
  16. $this->image = imagecreatefrompng($filename);
  17. }
  18. }
  19. function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) {
  20. if( $image_type == IMAGETYPE_JPEG ) {
  21. imagejpeg($this->image,$filename,$compression);
  22. } elseif( $image_type == IMAGETYPE_GIF ) {
  23. imagegif($this->image,$filename);
  24. } elseif( $image_type == IMAGETYPE_PNG ) {
  25. imagepng($this->image,$filename);
  26. }
  27. if( $permissions != null) {
  28. chmod($filename,$permissions);
  29. }
  30. }
  31. function output($image_type=IMAGETYPE_JPEG) {
  32. if( $image_type == IMAGETYPE_JPEG ) {
  33. imagejpeg($this->image);
  34. } elseif( $image_type == IMAGETYPE_GIF ) {
  35. imagegif($this->image);
  36. } elseif( $image_type == IMAGETYPE_PNG ) {
  37. imagepng($this->image);
  38. }
  39. }
  40. function getWidth() {
  41. return imagesx($this->image);
  42. }
  43. function getHeight() {
  44. return imagesy($this->image);
  45. }
  46. function resizeToHeight($height) {
  47. $ratio = $height / $this->getHeight();
  48. $width = $this->getWidth() * $ratio;
  49. $this->resize($width,$height);
  50. }
  51. function resizeToWidth($width) {
  52. $ratio = $width / $this->getWidth();
  53. $height = $this->getheight() * $ratio;
  54. $this->resize($width,$height);
  55. }
  56. function scale($scale) {
  57. $width = $this->getWidth() * $scale/100;
  58. $height = $this->getheight() * $scale/100;
  59. $this->resize($width,$height);
  60. }
  61. function resize($width,$height) {
  62. $new_image = imagecreatetruecolor($width, $height);
  63. imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
  64. $this->image = $new_image;
  65. }
  66. }


Czy potraficie pomóc?