Esempio n. 1
0
 /**
  * @param \DarkLuk42\BoundingBox $bb area to check for cropping
  * @param \DarkLuk42\Color       $color color to be cropped
  * @param bool                   $cropTransparent if colors with alpha on invisible should be cropped too
  *
  * @return \DarkLuk42\BoundingBox area to be cropped
  */
 public function cropRightByColor(BoundingBox $bb, Color $color, $cropTransparent = true)
 {
     $binaryColor = $color->toBinary();
     // right to left
     for ($x = $bb->getRight(); $x >= $bb->getLeft(); $x--) {
         for ($y = $bb->getTop(); $y <= $bb->getBottom(); $y++) {
             if ($binaryColor != $this->colorAt($x, $y) && (!$cropTransparent || $this->colorAt($x, $y) >> 24 < 127)) {
                 break 2;
             }
         }
         $bb->setWidthByRight($x);
     }
     return $bb;
 }
Esempio n. 2
0
 public function scaleAs(BoundingBox $from, BoundingBox $to)
 {
     $this->scaleWidth($to->getWidth() / $from->getWidth());
     $this->addLeft(($to->getLeft() - $from->getLeft()) / $to->getWidth() * $this->getWidth());
     $this->scaleHeight($to->getHeight() / $from->getHeight());
     $this->addTop(($to->getTop() - $from->getTop()) / $to->getHeight() * $this->getHeight());
 }