<?php
declare(strict_types=1);

$image = imagecreatetruecolor(8, 6);
$background = imagecolorallocate($image, 238, 238, 238);
imagefill($image, 0, 0, $background);
$red = imagecolorallocate($image, 220, 60, 50);
$blue = imagecolorallocate($image, 20, 110, 190);
imagefilledrectangle($image, 1, 1, 4, 3, $red);
imagefilledrectangle($image, 4, 3, 6, 4, $blue);
imagesetpixel($image, 1, 2, $blue);
$crop = imagecrop($image, ["x" => 1, "y" => 1, "width" => 2, "height" => 3]);
echo imagesx($crop), "x", imagesy($crop), "\n";
echo imagesx($image), "x", imagesy($image), "\n";
