Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Własna "klasa" i biblioteka gd
artisan
post
Post #1





Grupa: Zarejestrowani
Postów: 41
Pomógł: 0
Dołączył: 14.11.2011
Skąd: Wieliczka

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


Napisałem "klasę" do zmieniania rozmiaru zdjęć. Wiem że nie jest profesjonalnie napisana, ale cóż. Problem jest taki że wynikiem działania nie jest zmieniony obrazek tylko napis obrazek- tak jakby nie było tego zdjęcia a jest.

size.php
  1. <?php
  2. include('resize.php');
  3. header('Content-Type: image/jpg');
  4. $klasa=new ResizeImg('lay.png',300);
  5. ?>

resize.php - klasa
  1. <?php
  2. class ResizeImg{
  3. private $url;
  4. private $mime_type;
  5. private $width;
  6. private $height;
  7. private $oldwidth;
  8. private $oldheight;
  9. private $root;
  10. private $new;
  11.  
  12. public function __construct($url,$width)
  13. {
  14. $this->url=$url;
  15. $this->mime_type=$this->get_mime();
  16. $this->width=$width;
  17. $this->height=$this->set_height();
  18. $this->oldwidth=$this->get_width();
  19. $this->oldheight=$this->get_height();
  20. }
  21. //wykonujemy wszystkie operacje
  22. public function __destruct()
  23. {
  24. $this->open();
  25. $this->create();
  26. $this->copy();
  27. }
  28. //pobieramy type-mime
  29. private function get_mime()
  30. {
  31. $mime=getimagesize($this->url);
  32. return $mime['mime'];
  33. }
  34. //pobieramy aktualna szerokosc
  35. private function get_width()
  36. {
  37. $width=getimagesize($this->url);
  38. return $width[0];
  39. }
  40. //pobieramy aktualna wysokosc
  41. private function get_height()
  42. {
  43. $height=getimagesize($this->url);
  44. return $height[1];
  45.  
  46. }
  47.  
  48. //ustalamy wysokosc
  49. private function set_height()
  50. {
  51. $height=($this->oldheight*$this->width)/$this->oldwidth;
  52. return $height;
  53. }
  54. //otwieramy aktualny obraz
  55. private function open()
  56. {
  57. switch($this->mime_type)
  58. {
  59. case 'image/jpeg' :
  60. $root=imagecreatefromjpeg($this->url);
  61. break;
  62. case 'image/gif' :
  63. $root=imagecreatefromgif($this->url);
  64. break;
  65. case 'image/png' :
  66. $root=imagecreatefrompng($this->url);
  67. break;
  68. }
  69. $this->root=$root;
  70. }
  71. //tworzymy nowy obraz
  72. private function create()
  73. {
  74. $this->new=imagecreatetruecolor($this->width,$this->height);
  75. }
  76. //tworzymy kopie obrazka
  77. private function copy()
  78. {
  79. imagecopyresampled($this->new, $this->root, 0, 0, 0, 0, $this->width, $this->height, $this->oldwidth, $this->oldheight);
  80. return imagejpeg($this->new);
  81. }
  82. }
  83. ?>


Podane zdjęcie znajduje się na serwerze.
http://artisan-programista.xaa.pl/size.php - przykład złego działania
Go to the top of the page
+Quote Post

Posty w temacie


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 - 15:57