Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Problem z zapisem obrazu i miniatury do roznych katalogow.
pracz
post
Post #1





Grupa: Zarejestrowani
Postów: 9
Pomógł: 0
Dołączył: 7.01.2011

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


Witam! Mam kod do tworzenia obrazu i jego miniatury z uploadowanego zdjecia:
  1.  
  2. $foto_tmp = $_FILES['userfoto']['tmp_name'];
  3. $foto_nazwa = $_FILES['userfoto']['name'];
  4. $foto_rozmiar = $_FILES['userfoto']['size'];
  5.  
  6. if(is_uploaded_file($foto_tmp))
  7. {
  8.  
  9. list($width_src,$height_src) = getimagesize($foto_tmp);
  10.  
  11.  
  12. /*++++++Wylicza wysokosc i szerokosc nowego obrazu+++++*/
  13.  
  14. if ( $width_src < $height_src )
  15. { $nheight = 350;
  16. $nheight_s= 96;
  17.  
  18. $nwidth = $width_src*$nheight/$height_src;
  19. $nwidth_s = $width_src*$nheight_s/$height_src;
  20. }
  21. elseif( $width_src > $height_src )
  22. { $nwidth = 400;
  23. $nwidth_s = 96;
  24.  
  25. $nheight = $nwidth/$width_src*$height_src;
  26. $nheight_s = $nwidth_s/$width_src*$height_src;
  27. }
  28.  
  29.  
  30.  
  31.  
  32.  
  33. $dst_img=imagecreatetruecolor($nwidth,$nheight);
  34. $dst_thumb=imagecreatetruecolor($nwidth_s,$nheight_s);
  35.  
  36. $src_img=ImageCreateFromJpeg($foto_tmp);
  37. $src_thumb=ImageCreateFromJpeg($foto_tmp);
  38.  
  39. $new=imagecopyresampled ($dst_img, $src_img, 0, 0, 0, 0, $nwidth, $nheight, $width_src,$height_src);
  40.  
  41.  
  42. $imagepath='photos';
  43. imagejpeg($dst_img, "7.jpeg", 100);
  44.  
  45. move_uploaded_file($new, $imagepath);
  46.  
  47.  
  48.  
  49.  
  50.  
  51. $new_s=imagecopyresampled ($dst_thumb, $src_thumb, 0, 0, 0, 0, $nwidth_s, $nheight_s, $width_src,$height_src);
  52.  
  53. $s_path='photos_s';
  54.  
  55. imagejpeg($dst_thumb, "8.jpeg", 100);
  56.  
  57.  
  58. if(move_uploaded_file($new_s, $s_path)){
  59. if(imagedestroy($foto_tmp))echo'ok';
  60. else echo'cos tu nie gra'; }
  61.  
  62.  
  63. }
  64.  
  65.  
  66.  
  67.  
  68. else echo'nie ma zdjecia';
  69.  


Niby wszystko ok (bynajmniej jesli chodzi o pomniejszanie) jednak obraz i miniatura zapisuja sie w katalogu glownym htdocs a nie w docelowych: $imagepath i $s_path.
Co jest nie tak?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 1)
ast89
post
Post #2





Grupa: Zarejestrowani
Postów: 23
Pomógł: 2
Dołączył: 26.09.2009

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


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


  1. wywołanie:
  2. $image = new SimpleImage();
  3. $image->load(_PICDIR_.$nazwa);
  4. $image->resize(133,175);
  5. $image->save(_THDIR_.$nazwa);
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 22.08.2025 - 22:28