getWidth(); $imageHeight = $image->getHeight(); for ($i = 0; $i <= $lines; $i++) { $image->addLine( x1: mt_rand(0, $imageWidth) + $i * mt_rand(0, $imageHeight), y1: mt_rand(0, $imageHeight), x2: mt_rand(0, $imageWidth), y2: mt_rand(0, $imageHeight), hexColor: $this->lineColors($colors) ); } return $image; } private function lineColors(array $colors): string { if (!empty($colors)) { return Arr::random($colors); } return '#' . str_pad(dechex(mt_rand(0, 0xFFFFFF)), 6, '0', STR_PAD_LEFT); } }