ImageUrl: What is the options `-rw` in some image link

50 Views Asked by At

I have a problem when load image with this url: "https://lh3.googleusercontent.com/sZl-o9TGNYXucrPNHesxaMLXajhcPYqw43zojzHJ-y1yYYeQaNtJMrPUQImKgak3paKOMbEm0Av0e5bKG8_z31m1xVGN8J3x-EIAfgeETIhrLxwsw7xWEGstIuwyKYuHjOLFPCcvqIBY944PWFHBhgSEsVERXJljVEwPTD1xpJHhi5gHieiZcjl-rJ734bFiDxG1GzTxkX5nRc9lkRhtNHMdHDOSswMU-dgp8itMF8lTdEztOYz_bE_8H2FxN5NtCBmeOvxTi7f31wM2zrAE7oOzzeVy1_hYLFAWuXJ0CNqDfc-J-Ui9HY1RILj9Z1nYvEKGGDSTiT3tzysWHO9Vn6rXDFKE9TUGNE1_Z9_EaQ7B_HIU_z7oq2Hmmikl1Ap5t7N_pEI44ZhUGbIVirHKJyvc2LgtJgczCeNEgH7SnvvYBCM-OMWX5MnB949rXYn678iZyz7Q16wjPMevr1IQU4zfdOE2xoJQi8x3FhpD2-3moUoilZRBR5OQi-KII4hRYrEaRFnAiGqYeFz3Rqwx_Yw97kROwh2AnfhT03700AHkFqmYobTXjq0Q3IQpjcYQZ3vbtw=w400-rw"

I know w400 means this gets the image resampled so the width is always 400 pixels, but -rw.

In iOS, I'm using Nuke to load image url to UIImageView, the above link work well in iOS 16 but iOS 13 not working. And, I recognize the problem is option -rw, it will work well without it

Do you guys have any ideas?

I can work around by removing -rw in that link, but it is not completely solved. There are some types of link, ex: "https://1.bp.blogspot.com/-ALD_DHOaeq4/XwCFhFY7eWI/AAAAAAAAWhI/IayZa7GHlZ4GNCvTHZ603zYF-PNHoq5KwCLcBGAsYHQ/w800-h400-rw/landscape_color_8.png"

--> Remove -rw is not safe at all.

1

There are 1 best solutions below

2
vignesh On

From the URL I assume that everything after = is the parameter read by the server to generate the image content.

Now we can remove the -rw which is only at the end of the URL like this,

let suffix = "-rw"
func removeRW(imageURL: String) -> String {
    var url: String = imageURL
    if url.hasSuffix(suffix) {
        url = String(url.dropLast(suffix.count))
    }
    return url
}

print(removeRW(imageURL:"http://www.some.come?bgdfsrejuf-rwdnfk=w400-rw"))
Out Put: http://www.some.come?bgdfsrejuf-rwdnfk=w400