Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: Zmiana rozmiaru obrazu w locie (programowanie obiektowe)
Forum PHP.pl > Forum > Przedszkole
pecik
Witam. Bardzo proszę p o pomoc, dopiero zaczynam i nie wiem jak do tego podejść. Chodzi mi o konkretny przykład. Jest wiele stron ze skryptami ale pliss, nie odsyłajcie mnie tam, bo chodzi mi o umiejętnie łączenie i tworzenie nowych :-).

Mam klasę obsługującą grafikę, ale nie kompletną. chodzi o to by pobrać zdjęcia i pozmieniać rozmiary.

Muszą sie w niej nnaley takie metody publiczne zmieniające rozmiar , i zachowujące kształt rectange:
resize_to_width(src, width,bg=null)
resize_to_height(src, height,bg=null)
resize_to_rectangle(src,width,height)


get_icon_16(src,bg)
get_icon_32, get_icon_64 i, get_icon_86 //pobranie ikony o roznych rozmiarach kolejno 16x16 pikseli itd.

Mogą być w tym jakieś dowolne prywatne funkcje , jeśli ułatwia.

Utworzona nowa klasa "graphics" musi dziedziczyć po fs_connect.
Ma operować na folderze common w np folderze głównym ma pobierać wiele obrazków/ ikon z jakiegoś katalogu, i je ustawiać.

  1.  
  2. <?
  3.  
  4. class access_fs_connex {
  5.  
  6. private $main_folder = 'common';
  7. public $buffer_l1 = array(); //pierwsza warstwa folderów
  8.  
  9. function __construct($path = NULL){
  10.  
  11. if($path!==NULL) $this->main_folder+='/'.$path;
  12. $this->buffer_fs($this->buffer_l1, $this->main_folder);
  13. }
  14.  
  15.  
  16. public function refresh(){
  17. $this->buffer_fs(&$this->buffer_l1, $this->main_folder);
  18. }
  19.  
  20. private function buffer_fs(&$table, $path){ // VOID //buforowanie folderu $path do tablicy $table
  21.  
  22. $mydir = dir($path);
  23. while($file_name = $mydir->read())
  24. {
  25. if($file_name!="." && $file_name!=".." && is_dir($path.'/'.$file_name))
  26. array_push($table, $file_name);
  27. }
  28.  
  29. }
  30.  
  31. private function is_folder_exists($folder_name){ // VOID //tworzenie folderu jeśli nie istnieje
  32.  
  33. foreach ($this->buffer_l1 as $item){
  34. if($item == $folder_name) return true;
  35. }
  36. return false;
  37. }
  38.  
  39. public function init_folder($folder_name){
  40.  
  41. if(!$this->is_folder_exists($folder_name)){
  42. @mkdir($this->main_folder.'/'.$folder_name, 0777);
  43.  
  44. }
  45. }
  46.  
  47. public function create_folder($sub_path, $new_folder_name){ //$main_patch bez bocznych slashy!
  48. @mkdir($this->main_folder.'/'.$sub_path.'/'.$new_folder_name, 0777);
  49. echo '<br>-created folder: '.$this->main_folder.'/'.$sub_path.'/'.$new_folder_name.' <br>';
  50. }
  51.  
  52. public function create_free_folder($full_path, $new_folder_name){ //$main_patch bez bocznych slashy!
  53. @mkdir($full_path.'/'.$new_folder_name, 0777);
  54. //echo '<br>-created folder: '.$this->main_folder.'/'.$sub_path.'/'.$new_folder_name.' <br>';
  55. }
  56.  
  57. public function get_path($folder_name){
  58. return $this->main_folder.'/'.$folder_name;
  59. }
  60.  
  61. function get_photos($sub_path = 'folder/folder'){
  62.  
  63. $ans = array();
  64. $mydir = dir($this->main_folder.'/'.$sub_path);
  65.  
  66. while($file_name = $mydir->read()){
  67. if($file_name!="." && $file_name!=".." && $this->is_ok_ext($file_name, array('jpg', 'jpeg', 'JPG','JPEG'))) array_push($ans, $file_name);
  68. }
  69. return $ans;
  70.  
  71. }
  72.  
  73. function get_photos_directly($path = 'common/folder/folder'){
  74.  
  75. $ans = array();
  76. $mydir = dir($path);
  77.  
  78. while($file_name = $mydir->read()){
  79. if($file_name!="." && $file_name!=".." && $this->is_ok_ext($file_name, array('jpg', 'jpeg', 'JPG','JPEG'))) array_push($ans, $file_name);
  80. }
  81. return $ans;
  82.  
  83. }
  84.  
  85. function is_ok_ext($name, $ext_table){
  86.  
  87. $un = explode('.', $name);
  88. for($i=0 ; $i<count($ext_table); $i++){
  89.  
  90. if($un[count($un)-1]==$ext_table[$i]){
  91. return true;
  92. }
  93.  
  94. }
  95. return false;
  96.  
  97. }
  98.  
  99. public function delTree($dir) {
  100.  
  101. if (file_exists($dir)) {
  102. $mydir = dir($dir);
  103.  
  104. while($file_name = $mydir->read()){
  105. if($file_name!="." && $file_name!=".."){
  106. @unlink($dir.'/'.$file_name);
  107. }
  108. }
  109. @rmdir($dir);
  110. }
  111.  
  112. }
  113.  
  114. public function get_kadr($sub_src, $w, $h){
  115. return '<img src=lib_panel/engines/mKadr.php?src='.$this->get_path($sub_src).'&w='.$w.'&h='.$h.'>';
  116. }
  117.  
  118. public function get_kadr_directly($src, $w, $h){
  119. return '<img src=lib_panel/engines/mKadr.php?src='.$src.'&w='.$w.'&h='.$h.'>';
  120. }
  121. }
  122. ?>
  123.  
Crozin
1) Kod powrzucaj w odpowiednie BBCode
2) Metody z serii: get_xx_icon(src, bg = null) zamień na: getIcon(src, bg = null, size = 32)
3) O tym jak skalować obrazy znajdziesz pewnie ze 10 000 wyników w Google i z 50 tutaj na forum
4) Nie napisałeś w czym konkretnie jest problem

btw: co to do cholery jest clasa?
pecik
Ok, dzieki za uwagi, wpomniałem ze jestem nowy.

Chodzi o to by pobrać obrazi/ikony i zmienić ich rozmiar na 4 rozne podane 16x16, 64x64, itd.
Zapisana ikona niech będzie tylko w jednym (oryginalnym) rozmiarze i resampling w locie dla tych innych rozmiarow , do wyboru przez nas
pecik
Ok , mam pare skryptów pomocnych i jak to terz wszystko połączyć? pomocy!! :-O

  1. <?php
  2. //resempling
  3. // plik
  4. $filename = 'test.jpg';
  5. $percent = 0.5;
  6.  
  7. header('Content-type: image/jpeg');
  8.  
  9.  
  10. list($width, $height) = getimagesize($filename);
  11. $new_width = $width * $percent;
  12. $new_height = $height * $percent;
  13.  
  14. // Resample
  15. $image_p = imagecreatetruecolor($new_width, $new_height);
  16. $image = imagecreatefromjpeg($filename);
  17. imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height);
  18.  
  19. // Output
  20. imagejpeg($image_p, null, 100);
  21.  
  22. ?>
  23.  


  1.  
  2.  
  3. <?php
  4.  
  5.  
  6.  
  7.  
  8. function resize_to_rectangle($src, $width, $height) {
  9.  
  10.  
  11. if ($width > $height) {
  12. $percentage = ($target / $width);
  13. } else {
  14. $percentage = ($src / $height);
  15. }
  16.  
  17. //zaokraglone wartosci
  18. $width = round($width * $percentage);
  19. $height = round($height * $percentage);
  20.  
  21. //zwraca nowy rozmiar
  22. return "width=\"$width\" height=\"$height\"";
  23.  
  24. }
  25.  
  26.  
  27.  
  28. ?>
  29.  
  30.  
  31.  



  1.  
  2. <?php
  3.  
  4.  
  5.  
  6.  
  7. function resize_to_rectangle($src, $width, $height) {
  8.  
  9.  
  10. if ($width > $height) {
  11. $percentage = ($target / $width);
  12. } else {
  13. $percentage = ($src / $height);
  14. }
  15.  
  16. //zaokraglone wartosci
  17. $width = round($width * $percentage);
  18. $height = round($height * $percentage);
  19.  
  20. //zwraca nowy rozmiar
  21. return "width=\"$width\" height=\"$height\"";
  22.  
  23. }
  24.  
  25.  
  26.  
  27. ?>
  28.  



Ociu
Proszę w pierwszym poście wstawić bbCode oraz nadać tematowi jakiś normalny tytuł. Do tego czytać swoje posty, bo z tego co widzę to jest literówka na literówce. Jeśli się to nie poprawi, to zamknę temat.
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.