MOON
Server: Apache
System: Linux nserver.cafsindia.com 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: cafsindia (1002)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: /home/cafsindia/snap.cafsinfotech.in/app/Helpers/FakeScreenshotGenerator.php
<?php

namespace App\Helpers;

use App\Contracts\ScreenshotService;
use App\Models\TimeInterval;
use Faker\Factory;

class FakeScreenshotGenerator
{
    private const SCREENSHOT_WIDTH = 1920;
    private const SCREENSHOT_HEIGHT = 1080;

    public static function runForTimeInterval(TimeInterval|int $timeInterval): void
    {
        $service = app()->make(ScreenshotService::class);

        $tmpFile = tempnam(sys_get_temp_dir(), 'cattr_screenshot');

        $image = imagecreatetruecolor(self::SCREENSHOT_WIDTH, self::SCREENSHOT_HEIGHT);
        $background = imagecolorallocate($image, random_int(0, 255), random_int(0, 255), random_int(0, 255));

        imagefill($image, 0, 0, $background);

        \imagejpeg($image, $tmpFile);
        imagedestroy($image);

        $service->saveScreenshot(
            $tmpFile,
            $timeInterval
        );

        unlink($tmpFile);
    }
}