Jestem w trakcie pisania modułu witryny skalującego obrazy, niestety nie mogę uporać się z błędem nie mam pojęcia o co kaman.
Efekt widoczny w przeglądarce to trzy jedynki
<?php
class cFileManagerGallery
{
//Obiekty
private $_model;
private $_view;
//Dane
private $_arFiles = array(); //Tablica zdjęć private $_imgW; //Szerokość obrazu
private $_imgH; //Wysokość obrazu
private $_newImgW; //Nowa szerokość obrazu
private $_newImgH; //Nowa wysokość obrazu
private $_ratio; //Stosunek szerokości do wysokości
private $_img; //Uchwyt aktualnego obrazu
//Uruchamia model, ustawia dane,
//skaluje pliki JPG, uruchamia view
public function __construct()
{
$this -> runModel();
$this -> setData();
$this -> scaleImg();
$this -> runView();
}
//Uruchamia model
private function runModel()
{
$this -> _model = new mFileManager('web/gallery/');
}
//Wczytuje wszystkie zdjęcia do tablicy _arFiles
private function setData()
{
$this -> _arFiles = ($this -> _model -> getData());
}
//Metoda odpowiedziala za przeskalowanie wszystkich
//obrazów z tablicy: _arFiles i zapisanie ich miniatur
//do tablicy: _arNewFles
private function scaleImg()
{
for($i = 0; $i < count($this -> _arFiles
); $i++) {
if(!($this -> _img = imagecreatefromjpeg('web/gallery/' . $this -> _arFiles[$i])))
{
echo 'Nie można otworzyć pliku: ' . $this -> _arFiles
[$i]; return false;
}
$this -> _imgW = imagesx($this -> _img);
$this -> _imgH = imagesy($this -> _img);
$this -> _ratio = $this -> _imgW / $this -> _imgH;
if($this -> _ratio > 1)
{
$this -> _newImgW = 150;
$this -> _newImgH = 150 / $this -> _ratio;
}
else
{
$this -> _newImgW = 150 * $this -> _ratio;
$this -> _newImgH = 150;
}
$tempImg = imagecreatetruecolor($this -> _newImgW, $this -> _newImgH);
imagecopyresampled($tempImg, $this -> _img, 0, 0, 0, 0, $this -> _newImgW,
$this -> _newImgH, $this -> _imgW, $this -> _imgH);
$this -> _arNewFiles[$i] = imagejpeg($tempImg, $i . '.jpg');
}
}
//Uruchamia widok
private function runView()
{
$this -> _view = new vFileManagerGallery($this -> _arFiles ,$this -> _arNewFiles);
}
}
?>
Ten post edytował lDoran 27.08.2010, 20:22:41