Skip to content

Novis\Image\Image::Axis

The direction in which flipped mirrors an image.

Image::Axis is declared in the class Novis\Image\Image.

Horizontal swaps left and right, like a mirror on the wall. Vertical swaps top and bottom, like the reflection in a lake. The size of the image stays the same.

To turn an image instead of mirroring it, use rotated.

Examples

Mirror left and right

<?nvs
// Shows what each `Image::Axis` does to the pixels of an image.
use Novis\Image\Image;
class Corner
{
public static function topLeft(Image $image): tainted string
{
array<mixed> $p = Core\Bytes::unpack(Core\Bytes::slice($image->raw()->pixels, 0, 4), 'C4');
return "{$p[0]} {$p[1]} {$p[2]}";
}
}
// An image of 2 by 2 pixels. The top row is red and green, and the bottom row is blue and white.
Image $tiles = Image::fromRaw({
width: 2,
height: 2,
pixels: Core\Encoding::fromHex('ff0000ff00ff00ff0000ffffffffffff'),
});
// The top-left pixel is red at the start, so the first line prints 255 0 0.
// After `Horizontal` it is green (0 255 0). After `Vertical` it is blue (0 0 255).
echo Corner::topLeft($tiles), "\n";
echo Corner::topLeft($tiles->flipped(Image::Axis::Horizontal)), "\n";
echo Corner::topLeft($tiles->flipped(Image::Axis::Vertical)), "\n";
Output
255 0 0
0 255 0
0 0 255