Created
December 13, 2015 13:37
-
-
Save Ray33/3b4e5b12db103d626859 to your computer and use it in GitHub Desktop.
Sample code to change image resolution in url
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected String replaceImageResolution(String images) { | |
int sqIndex = images.indexOf("sq"); | |
String f; | |
if (sqIndex != -1){ | |
String prefix = images.substring(0,sqIndex + 3); | |
String suffix = images.substring(sqIndex + 3); | |
char c; | |
int startTrim = 0; | |
for(int i=0; i< suffix.length();i++){ | |
c = suffix.charAt(i); | |
if (c >= '0' && c <= '9'){ | |
startTrim++; | |
}else{ | |
break; | |
} | |
} | |
f = prefix + "300" + suffix.substring(startTrim); | |
}else if (images.indexOf("00x")!=-1){ | |
String prefix = images.substring(0,images.indexOf("00x") -1); | |
String suffix = images.substring(images.indexOf("00x") + 3); | |
int startTrim = 0; | |
for(int i=0; i< suffix.length();i++){ | |
char c = suffix.charAt(i); | |
if (c != '-'){ | |
startTrim++; | |
}else{ | |
break; | |
} | |
} | |
f = prefix + "300x300" + suffix.substring(startTrim); | |
}else{ | |
f = images; | |
} | |
return f; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment