Skip to content

Instantly share code, notes, and snippets.

@Ray33
Created December 13, 2015 13:37
Show Gist options
  • Save Ray33/3b4e5b12db103d626859 to your computer and use it in GitHub Desktop.
Save Ray33/3b4e5b12db103d626859 to your computer and use it in GitHub Desktop.
Sample code to change image resolution in url
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