Skip to content

Instantly share code, notes, and snippets.

@joseadrian
Created April 18, 2013 21:18
Show Gist options
  • Save joseadrian/5416308 to your computer and use it in GitHub Desktop.
Save joseadrian/5416308 to your computer and use it in GitHub Desktop.
Redimensionar imágenes manteniendo el ratio para un máximo ancho y alto.
var redimensionar = function(srcWidth, srcHeight, maxWidth, maxHeight) {
var ratio = [maxWidth / srcWidth, maxHeight / srcHeight ];
ratio = Math.min(ratio[0], ratio[1]);
// Mantener el ancho y alto normal?
if(ratio < 1){
srcWidth = srcWidth*ratio;
srcHeight = srcHeight*ratio;
}
return { width:srcWidth*ratio, height :srcHeight*ratio };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment