/** * @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; }
public static function containedByBoth(BoundingBox $bb1, BoundingBox $bb2) { $left = max($bb1->getLeft(), $bb2->getLeft()); $top = max($bb1->getLeft(), $bb2->getLeft()); $right = min($bb1->getRight(), $bb2->getRight()); $bottom = min($bb1->getBottom(), $bb2->getBottom()); $bb = new self($left, $top, 0, 0); $bb->setWidthByRight($right); $bb->setHeightByBottom($bottom); return $bb; }