8000 Upload photos from the library as JPEG instead of HEIC by nuno-vieira · Pull Request #767 · GetStream/stream-chat-swiftui · GitHub
[go: up one dir, main page]

Skip to content

Upload photos from the library as JPEG instead of HEIC #767

New issue

Have a question 8000 about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
# Upcoming

### 🔄 Changed
- Uploading a HEIC photo from the library is now converted to JPEG for better compatibility [#767](https://github.com/GetStream/stream-chat-swiftui/pull/767)

# [4.73.0](https://github.com/GetStream/stream-chat-swiftui/releases/tag/4.73.0)
_February 28, 2025_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ final class ImagePickerCoordinator: NSObject, UIImagePickerControllerDelegate, U
didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey: Any]
) {
if let uiImage = info[.originalImage] as? UIImage,
let imageURL = try? uiImage.temporaryLocalFileUrl() {
let imageURL = try? uiImage.saveAsJpgToTemporaryUrl() {
let addedImage = AddedAsset(
image: uiImage,
id: UUID().uuidString,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public struct PhotoAttachmentCell: View {
.allowsHitTesting(true)
.onTapGesture {
withAnimation {
if let assetURL = assetURL {
if let assetURL = assetJpgURL() {
onImageTap(
AddedAsset(
image: image,
Expand Down Expand Up @@ -193,4 +193,13 @@ public struct PhotoAttachmentCell: View {
}
}
}

/// The original photo is usually in HEIC format.
/// This makes sure that the photo is converted to JPG.
/// This way it is more compatible with other platforms.
private func assetJpgURL() -> URL? {
guard let assetURL = assetURL else { return nil }
guard let assetData = try? Data(contentsOf: assetURL) else { return nil }
return try? UIImage(data: assetData)?.saveAsJpgToTemporaryUrl()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ extension UIImage {
}

extension UIImage {
func temporaryLocalFileUrl() throws -> URL? {
func saveAsJpgToTemporaryUrl() throws -> URL? {
guard let imageData = jpegData(compressionQuality: 1.0) else { return nil }
let imageName = "\(UUID().uuidString).jpg"
let documentDirectory = NSTemporaryDirectory()
Expand Down
Loading
0