kean / Nuke

Image loading system
https://kean.blog/nuke
MIT License
8.16k stars 529 forks source link

Question: Discover Longest Image Size For Preprocessor #814

Open rehatkathuria opened 2 months ago

rehatkathuria commented 2 months ago

Is it possible to determine whether an image's width or height is bigger? Or possible to write a processor? I'd like to be able to set a value to the longer edge, regardless of which it is

LazyImage(url: asset.url)
    .processors(
        [
            .resize(longerPlane: 99)
        ]
    )
kean commented 2 months ago

By default, the resize processors scales the image to fill the provided area. See https://kean-docs.github.io/nuke/documentation/nuke/imageprocessing/resize(size:unit:contentmode:crop:upscale:) for more info and see if that works for you.

Yes, it's fairly easy to write a custome image processor. Related guide: https://kean-docs.github.io/nuke/documentation/nuke/image-processing/. Alternatively, you can create one on the fly using a closure https://kean-docs.github.io/nuke/documentation/nuke/imageprocessing/process(id:_:).