private static function getRemoteFileSize($imageUrl)
    {
        $result = curl_init($imageUrl);
        if (!$result) {
            return 0;
        }

        curl_setopt($result, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($result, CURLOPT_HEADER, true);
        curl_setopt($result, CURLOPT_NOBODY, true);

        curl_exec($result);
        $imageSize = curl_getinfo($result, CURLINFO_CONTENT_LENGTH_DOWNLOAD);
        curl_close($result);

        return (int) $imageSize;
    }