Beispiel #1
0
 /**
  * ctreates round corners
  * @param string   destination image key
  * @param integer  radius (0-100)
  * @param integer  rounding quality (1-5)
  * @return void
  */
 function make_roundcorners($sDestKey, $radius = 5, $rate = 5)
 {
     $width = ImagesX($this->img[$sDestKey]);
     $height = ImagesY($this->img[$sDestKey]);
     ImageAlphablending($this->img[$sDestKey], false);
     ImageSaveAlpha($this->img[$sDestKey], true);
     $rs_radius = $radius * $rate;
     $rs_size = $rs_radius * 2;
     $corner = ImageCreateTrueColor($rs_size, $rs_size);
     ImageAlphablending($corner, false);
     $trans = ImageColorAllocateAlpha($corner, 255, 255, 255, 127);
     ImageFill($corner, 0, 0, $trans);
     $positions = array(array(0, 0, 0, 0), array($rs_radius, 0, $width - $radius, 0), array($rs_radius, $rs_radius, $width - $radius, $height - $radius), array(0, $rs_radius, 0, $height - $radius));
     foreach ($positions as $pos) {
         ImageCopyResampled($corner, $this->img[$sDestKey], $pos[0], $pos[1], $pos[2], $pos[3], $rs_radius, $rs_radius, $radius, $radius);
     }
     $lx = $ly = 0;
     $i = -$rs_radius;
     $y2 = -$i;
     $r_2 = $rs_radius * $rs_radius;
     for (; $i <= $y2; $i++) {
         $y = $i;
         $x = sqrt($r_2 - $y * $y);
         $y += $rs_radius;
         $x += $rs_radius;
         ImageLine($corner, $x, $y, $rs_size, $y, $trans);
         ImageLine($corner, 0, $y, $rs_size - $x, $y, $trans);
         $lx = $x;
         $ly = $y;
     }
     foreach ($positions as $i => $pos) {
         ImageCopyResampled($this->img[$sDestKey], $corner, $pos[2], $pos[3], $pos[0], $pos[1], $radius, $radius, $rs_radius, $rs_radius);
     }
     ImageDestroy($corner);
 }
Beispiel #2
0
 /**
  * Закругленные углы
  * 
  * @param mixed $img  дескриптор изображения
  * @param mixed $cornercolor  цвет углов в 16-ной кодировке. Если false - прозрачный
  * @param mixed $radius  радиус закругления
  * @param mixed $rate  сглаживание закругления, максимум - 20
  */
 private function roundCornersGD(&$img, $cornercolor, $radius = 5, $rate = 5)
 {
     if ($radius <= 0) {
         return false;
     }
     if ($rate <= 0) {
         $rate = 5;
     }
     if ($radius > 100) {
         $radius = 100;
     }
     if ($rate > 20) {
         $rate = 20;
     }
     $width = ImagesX($img);
     $height = ImagesY($img);
     $radius = $width <= $height ? round($width / 100 * $radius / 2) : round($height / 100 * $radius / 2);
     $rs_radius = $radius * $rate;
     $rs_size = $rs_radius * 2;
     ImageAlphablending($img, false);
     ImageSaveAlpha($img, true);
     $corner = ImageCreateTrueColor($rs_size, $rs_size);
     ImageAlphablending($corner, false);
     if ($cornercolor === false) {
         $this->oImg['type'] = IMAGETYPE_PNG;
     }
     if ($this->oImg['type'] == IMAGETYPE_PNG) {
         $trans = ImageColorAllocateAlpha($corner, 255, 255, 255, 127);
     } else {
         $trans = ImageColorAllocateAlpha($corner, (int) ($cornercolor % 0x1000000 / 0x10000), (int) ($cornercolor % 0x10000 / 0x100), $cornercolor % 0x100, 0);
     }
     imagefilledrectangle($corner, 0, 0, $rs_size, $rs_size, $trans);
     $positions = array(array(0, 0, 0, 0), array($rs_radius, 0, $width - $radius, 0), array($rs_radius, $rs_radius, $width - $radius, $height - $radius), array(0, $rs_radius, 0, $height - $radius));
     foreach ($positions as $pos) {
         ImageCopyResampled($corner, $img, $pos[0], $pos[1], $pos[2], $pos[3], $rs_radius, $rs_radius, $radius, $radius);
     }
     $lx = $ly = 0;
     $i = -$rs_radius;
     $y2 = -$i;
     $r_2 = $rs_radius * $rs_radius;
     for (; $i <= $y2; $i++) {
         $y = $i;
         $x = sqrt($r_2 - $y * $y);
         $y += $rs_radius;
         $x += $rs_radius;
         ImageLine($corner, $x, $y, $rs_size, $y, $trans);
         ImageLine($corner, 0, $y, $rs_size - $x, $y, $trans);
         $lx = $x;
         $ly = $y;
     }
     foreach ($positions as $i => $pos) {
         ImageCopyResampled($img, $corner, $pos[2], $pos[3], $pos[0], $pos[1], $radius, $radius, $rs_radius, $rs_radius);
     }
     ImageDestroy($corner);
 }