Skip to content
New issue

Have a question 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

JPG not resizing, just black #782

Closed
tillkruss opened this issue May 11, 2024 · 2 comments
Closed

JPG not resizing, just black #782

tillkruss opened this issue May 11, 2024 · 2 comments
Labels

Comments

@tillkruss
Copy link

I'm noticing some .jpg result in a black image when resized. Is that an issue with the file, Nuke, or my code?

import Nuke
import NukeUI
import SwiftUI

struct Test: View {
    let url = "https://image.tmdb.org/t/p/original/f0JpsMQ9oEjKBD66Ky3qK3z7LGT.jpg"

    var body: some View {
        LazyImage(request: imageRequest(url)) { state in
            if let image = state.image {
                let _ = print("success")
                image.resizable()
            } else if state.error != nil {
                let _ = print(state.error)
            } else {
                Text("loading")
            }
        }
    }

    func imageRequest(_ urlString: String?) -> ImageRequest {
        let url = URL(string: urlString!)
        let request = URLRequest(url: url!, timeoutInterval: 5)

        return ImageRequest(
            urlRequest: request,
            processors: [
                .resize(size: CGSize(width: 325, height: 488))
            ]
        )
    }
}

#Preview {
    Test()
}
@kean kean added the bug label May 18, 2024
@kean
Copy link
Owner

kean commented May 18, 2024

Hey, thanks for the report, @tillkruss. It is a defect in the framework. The resize method does not handle grayscale images like this correctly.

RCA (for future reference)

  • The input image is grayscale (8 bpp pixel format) and with no alpha channel
  • The framework tries to create CGContext with the grayscale CS, 8 bpp and CGImageGetAlphaInfo.nonSkipLast, an unsupported combination
  • The framework expects the CGContext init to fail and fall back to a safe combination of parameters supported on all Apple devices. But CGContext does get created anyway and fails to render images correctly.

Fixed in v12.7.

@kean kean closed this as completed May 18, 2024
@tillkruss
Copy link
Author

Thanks a lot! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants