Created
October 5, 2022 20:21
-
-
Save dfaker/89a537a245cf0444c1a3aee1bf2d2a41 to your computer and use it in GitHub Desktop.
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
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