public static function imageProxy($url, $filename, $directory, $overwrite = null)
    {
        $allowedmimetype = [ 'image/gif', 'image/jpeg', 'image/png', 'image/x-icon' ];

        $localpath = $directory . '/noapi_' . $filename;

        if (! $overwrite && file_exists($localpath)) return $localpath;

        $image = file_get_contents($url);
        $finfo = new \finfo(FILEINFO_MIME_TYPE);
        $mimetype = $finfo->buffer($image);

        if (! in_array($mimetype, $allowedmimetype)) return false;

        if (file_put_contents($localpath, $image) === false) return false;

        return $localpath;
    }