Skip to content

Instantly share code, notes, and snippets.

@dfaker
Created October 5, 2022 20:21
Show Gist options
  • Save dfaker/89a537a245cf0444c1a3aee1bf2d2a41 to your computer and use it in GitHub Desktop.
Save dfaker/89a537a245cf0444c1a3aee1bf2d2a41 to your computer and use it in GitHub Desktop.
onUiUpdate(function(){
gradioApp().querySelectorAll('button img').forEach(function(e){
if(!e.classList.contains('downsized')){
if(e.naturalHeight != e.clientHeight || e.naturalWidth != e.clientWidth){
var canvas = document.createElement("canvas");
var ar = e.naturalHeight/e.naturalWidth
canvas.width = e.clientWidth;
canvas.height = e.clientHeight*ar;
var ctx = canvas.getContext("2d");
ctx.drawImage(e, 0, 0, e.clientWidth, e.clientHeight*ar);
e.src = canvas.toDataURL('img/png');
e.classList.add('downsized');
console.log(e);
}
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment