/** * */ public function showimage() { $image = imagecreateTruecolor($this->width, $this->height); $width = imagesx($image); $height = imagesy($image); $black = imagecolorallocate($image, 0, 0, 0); $white = imagecolorallocate($image, 255, 255, 255); $red = imagecolorallocatealpha($image, 255, 0, 0, 75); $green = imagecolorallocatealpha($image, 0, 255, 0, 75); $blue = imagecolorallocatealpha($image, 0, 0, 255, 75); imagefilledrectangle($image, 0, 0, $width, $height, $white); for ($i = 0; $i < 50; $i++) { imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $red); imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $green); imagefilledellipse($image, ceil(rand(5, 145)), ceil(rand(0, 35)), 30, 30, $blue); } imagefilledrectangle($image, 0, 0, $width, 0, $black); imagefilledrectangle($image, $width - 1, 0, $width - 1, $height - 1, $black); imagefilledrectangle($image, 0, 0, 0, $height - 1, $black); imagefilledrectangle($image, 0, $height - 1, $width, $height - 1, $black); imagettftext($image, 15, 0, intval(($width - strlen($this->code) * 10) / 2), intval($height / 2 + 7), $black, $this->font, $this->code); header('Content-type: image/jpeg'); imagejpeg($image); imagedestroy($image); }
/** * @param $width * @param $height * @param bool|True $protectrate * @throws Exception */ public function resize($width, $height, $protectrate = True) { if ($height == Null and $width != Null) { $rate = ceil($this->info['width'] / $width); $new = imagecreateTruecolor($width, ceil($this->info['height'] / $rate)); imagecopyresized($new, $this->copy, 0, 0, 0, 0, $width, ceil($this->info['height'] / $rate), $this->info['width'], $this->info['height']); imagedestroy($this->copy); $this->copy = $new; } elseif ($height != Null and $width == Null) { $rate = ceil($this->info['height'] / $height); $new = imagecreateTruecolor(ceil($this->info['width'] / $rate), $height); imagecopyresized($new, $this->copy, 0, 0, 0, 0, ceil($this->info['width'] / $rate), $height, $this->info['width'], $this->info['height']); imagedestroy($this->copy); $this->copy = $new; } elseif ($height != Null and $width != Null and $protectrate == True) { $rate = ceil($this->info['width'] / $width); $newheight = ceil($this->info['height'] / $rate); $start = ($newheight - $height) / 2; if ($start > 0) { $new = imagecreateTruecolor($width, $newheight); imagecopyresized($new, $this->copy, 0, 0, 0, 0, $width, $newheight, $this->info['width'], $this->info['height']); imagedestroy($this->copy); $this->copy = $new; $this->crop(0, $start, $width, $height); } else { $this->resize($width, $height, False); } } elseif ($height != Null and $width != Null and $protectrate == False) { $new = imagecreateTruecolor($width, $height); imagecopyresized($new, $this->copy, 0, 0, 0, 0, $width, $height, $this->info['width'], $this->info['height']); imagedestroy($this->copy); $this->copy = $new; } else { throw new Exception('Compelled to at least one of the parameters values to be entered!'); } }