<?php

use Core\Db;

class Images
{
    public static function getSrc(int $id): string
    {
        $i = Db::getRow('select mime_type, img from images where id = ?', [$id]);
        return 'data:' . $i['mime_type'] . ';base64,' . base64_encode($i['img']);
    }

    public static function getSrcByName(string $name): string
    {
        $i = Db::getRow('select mime_type, img from images where id = (select logo from clan where name = ?)', [$name]);
        return 'data:' . $i['mime_type'] . ';base64,' . base64_encode($i['img']);
    }

    public static function getJson(int $id)
    {
        $stmt = Db::getRow('select mime_type, img from images where id = ?', [$id]);
        if (!$stmt) {
            $stmt = [];
        }
        return json_encode($stmt);
    }
}