Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *
- *
- * @param int $width
- * @param int $height
- * @param string $default
- */
- public function resize($width = 0, $height = 0, $default = '') {
- if (!$this->width || !$this->height) {
- return;
- }
- $width = ($width > 0) ? $width : $this->width;
- $height = ($height > 0) ? $height : $this->height;
- $xpos = 0;
- $ypos = 0;
- $scale = 1;
- $scale_w = $width / $this->width;
- $scale_h = $height / $this->height;
- if ($default == 'w') {
- $scale = $scale_w;
- } elseif ($default == 'h') {
- $scale = $scale_h;
- } else {
- $scale = min($scale_w, $scale_h);
- }
- if ($scale == 1 && $scale_h == $scale_w && $this->mime != 'image/png') {
- return;
- }
- $new_width = (int)($this->width * $scale);
- $new_height = (int)($this->height * $scale);
- $image_old = $this->image;
- $this->image = imagecreatetruecolor($new_width, $new_height);
- if ($this->mime == 'image/png') {
- imagealphablending($this->image, false);
- imagesavealpha($this->image, true);
- $background = imagecolorallocatealpha($this->image, 255, 255, 255, 127);
- imagecolortransparent($this->image, $background);
- } else {
- $background = imagecolorallocate($this->image, 255, 255, 255);
- }
- imagefilledrectangle($this->image, 0, 0, $new_width, $new_height, $background);
- imagecopyresampled($this->image, $image_old, $xpos, $ypos, 0, 0, $new_width, $new_height, $this->width, $this->height);
- imagedestroy($image_old);
- $this->width = $new_width;
- $this->height = $new_height;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement