*/ protected function extractExifData(string $input): CollectionInterface { if (!function_exists('exif_read_data')) { return new Collection(); } try { // source might be file path $source = self::readableFilePathOrFail($input); } catch (Throwable) { try { // source might be stream resource $source = self::buildStreamOrFail($input); } catch (RuntimeException) { return new Collection(); } } try { // extract exif data $data = @exif_read_data($source, null, true); } catch (Exception) { $data = []; } finally { if (is_resource($source)) { fclose($source); } } return new Collection(is_array($data) ? $data : []); } /** * Decodes given base64 encoded data. * * @throws InvalidArgumentException * @throws DecoderException */ protected function decodeBase64Data(mixed $input): string { if (!is_string($input) && !$input instanceof Stringable) { throw new InvalidArgumentException( 'Base64-encoded data must be either of type string or instance of Stringable', ); } $decoded = base64_decode((string) $input, true); if ($decoded === false) { throw new DecoderException('Input is not valid Base64-encoded data'); } if (base64_encode($decoded) !== str_replace(["\n", "\r"], '', (string) $input)) { throw new DecoderException('Input is not valid Base64-encoded data'); } return $decoded; } }