Czy ta klasa jest już dobrą próbą programowania obiektowego? W dobrym kierunku idę?
<?php
class Thumbnail
{
public $name;
private $img;
private $width;
private $height;
private $img_t;
private $width_t = 150;
private $height_t = 150;
public function __construct($name)
{
$this->name = $name;
$this->img = imagecreatefromjpeg($this->name);
$this->width = imagesx($this->img);
$this->height = imagesy($this->img);
}
public function createThumb()
{
$this->img_t = imagecreatetruecolor($this->width_t, $this->height_t);
imagecopyresampled($this->img_t, $this->img, 0, 0, 0, 0, $this->width_t, $this->height_t, $this->width, $this->height);
imagejpeg($this->img_t, 'thumb_'.$this->name, 100);
}
public function __destruct()
{
imagedestroy($this->img);
imagedestroy($this->img_t);
}
}
$oThumb = new Thumbnail('20120229028.jpg');
$oThumb->createThumb();
?>
@edit:
Oczywiście, można by dodać jeszcze możliwość dodawania rozmiaru miniatury (opcjonalna rzecz). Ale ogólnie chcę wiedzieć, czy programowanie obiektowe (takie typowe) idzie w tym kierunku, jak ja napisałem tą klasę.
@edit2:
No i zrobiłem tylko dla JPG, oczywiście normalnie powinno się zczytać rozszerzenie (np. dla JPG, GIF i PNG).