function resize() { $x = $this->getWidth(); $y = $this->getHeight(); if($this->rodzaj == "pionowy") { $width = 90; $radio = $x / $width; if($radio < 0) { $height = $y * $radio; $height = (int)$height; } elseif($radio > 0) { $height = $y / $radio; $height = (int)$height; } $new_image = imagecreatetruecolor($width, $height); imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight()); $this->image = $new_image; } elseif($this->rodzaj == "poziomy") { $height = 90; $radio = $y / $height; if($radio < 0) { $width = $x * $radio; $width = (int)$width; } elseif($radio > 0) { $width = $x / $radio; $width = (int)$width; } $new_image = imagecreatetruecolor($width, $height); imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight()); $this->image = $new_image; } }
Natomiast ta nie:
function resize() { $x = $this->getWidth(); $y = $this->getHeight(); if($this->rodzaj == "pionowy") { $width = 90; $radio = $x / $width; if($radio < 0) { $height = $y * $radio; $height = (int)$height; } elseif($radio > 0) { $height = $y / $radio; $height = (int)$height; } } elseif($this->rodzaj == "poziomy") { $height = 90; $radio = $y / $height; if($radio < 0) { $width = $x * $radio; $width = (int)$width; } elseif($radio > 0) { $width = $x / $radio; $width = (int)$width; } } $new_image = imagecreatetruecolor($width, $height); imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight()); $this->image = $new_image; }
Kod jest mój i stąd pytanie: czemu muszę dodawać 2 razy ten fragment:
$new_image = imagecreatetruecolor($width, $height); imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight()); $this->image = $new_image;
A nie jeden tak jak w drugim przykładzie?