Resize function (not optimized)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
public function resize($dimensions=array(), $limited=true)
{
//Set image dementions
if($limited AND ($this->GetImageHeight() > $dimensions['height'] OR $this->GetImageWidth() > $dimensions['width']) )
{
if( $this->GetImageHeight() > $this->GetImageWidth() )
{
if($dimensions['height'] < $dimensions['width'])
$dimensions['width'] = floor($dimensions['height']*($this->GetImageWidth()/$this->GetImageHeight()));
else
$dimensions['height'] = floor($dimensions['width']*($this->GetImageWidth()/$this->GetImageHeight()));
$height = $dimensions['height'];
$width = floor(($dimensions['height']/$this->GetImageHeight())*$this->GetImageWidth());
if( $width > $dimensions['width'] )
{
$width = $dimensions['width'];
$height = floor(($dimensions['width']/$this->GetImageWidth())*$this->GetImageHeight());
}
}
else
{
if($dimensions['height'] < $dimensions['width'])
$dimensions['width'] = floor($dimensions['height']*($this->GetImageWidth()/$this->GetImageHeight()));
else
$dimensions['height'] = floor($dimensions['width']*($this->GetImageWidth()/$this->GetImageHeight()));
$width = $dimensions['width'];
$height = floor(($dimensions['width']/$this->GetImageWidth())*$this->GetImageHeight());
if( $height > $dimensions['height'] )
{
$height = $dimensions['height'];
$width = floor(($dimensions['height']/$this->GetImageHeight())*$this->GetImageWidth());
}
}
$this->resized = imagecreatetruecolor($width, $height);
imagecopyresampled( $this->resized, $this->resource, 0, 0, 0, 0, $dimensions['width'], $dimensions['height'], $this->GetImageWidth(), $this->GetImageHeight() );
imagedestroy($this->resource);
$this->resource = &$this->resized;
}
}