husnjak/IGDB-SWIFT-API

Add Image builder

husnjak opened this issue · 2 comments

It is hard to handle image urls and image sizes.
I should create a function that builds the urls for me

example code:

func fetchImages( for imagePref : ImagePref, doubleSize : Bool ,  image : UIImageView, _ url : String) {
        var urlBase : String = ""

        switch imagePref {
        case .cover_small :
            urlBase = "cover_small"
        case .screenshot_med :
            urlBase = "screenshot_med"
        case .cover_big :
            urlBase = "cover_big"
        case .logo_med :
            urlBase = "logo_med"
        case .screenshot_big :
            urlBase = "screenshot_big"
        case .screenshot_huge :
            urlBase = "screenshothuge"
        case .thumb :
            urlBase = "thumb"
        case .micro :
            urlBase = "micro"
        case .hd :
            urlBase = "720p"
        case .fullHd :
            urlBase = "1080p"
        }

        if doubleSize {
            let url = URL(string: "https://images.igdb.com/igdb/image/upload/t(urlBase)2x/(url).jpg")
            gameImage.kf.setImage(with: url)

        } else {
            let url = URL(string: "https://images.igdb.com/igdb/image/upload/t(urlBase)/(url).jpg")
            gameImage.kf.setImage(with: url)
        }
    }

implemented Image Builder

jmshgs commented

is it possible to use the 2x / doubleSize image url today? I don't see a way right now