2022-09-22 17:37:57 +00:00
|
|
|
/**
|
|
|
|
* temporary fix for https://github.com/AUTOMATIC1111/stable-diffusion-webui/issues/668
|
|
|
|
* @see https://github.com/gradio-app/gradio/issues/1721
|
|
|
|
*/
|
|
|
|
function imageMaskResize() {
|
|
|
|
const canvases = gradioApp().querySelectorAll('#img2maskimg .touch-none canvas');
|
2023-05-17 12:46:58 +00:00
|
|
|
if (!canvases.length) {
|
|
|
|
window.removeEventListener('resize', imageMaskResize);
|
|
|
|
return;
|
2022-09-22 17:37:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const wrapper = canvases[0].closest('.touch-none');
|
|
|
|
const previewImage = wrapper.previousElementSibling;
|
|
|
|
|
2023-05-17 12:46:58 +00:00
|
|
|
if (!previewImage.complete) {
|
|
|
|
previewImage.addEventListener('load', imageMaskResize);
|
2022-09-22 17:37:57 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const w = previewImage.width;
|
|
|
|
const h = previewImage.height;
|
|
|
|
const nw = previewImage.naturalWidth;
|
|
|
|
const nh = previewImage.naturalHeight;
|
|
|
|
const portrait = nh > nw;
|
|
|
|
|
2023-05-17 12:46:58 +00:00
|
|
|
const wW = Math.min(w, portrait ? h / nh * nw : w / nw * nw);
|
|
|
|
const wH = Math.min(h, portrait ? h / nh * nh : w / nw * nh);
|
2022-09-22 17:37:57 +00:00
|
|
|
|
|
|
|
wrapper.style.width = `${wW}px`;
|
|
|
|
wrapper.style.height = `${wH}px`;
|
2022-10-17 03:25:34 +00:00
|
|
|
wrapper.style.left = `0px`;
|
|
|
|
wrapper.style.top = `0px`;
|
2022-09-22 17:37:57 +00:00
|
|
|
|
2023-05-17 12:46:58 +00:00
|
|
|
canvases.forEach(c => {
|
2022-09-22 17:37:57 +00:00
|
|
|
c.style.width = c.style.height = '';
|
|
|
|
c.style.maxWidth = '100%';
|
|
|
|
c.style.maxHeight = '100%';
|
|
|
|
c.style.objectFit = 'contain';
|
|
|
|
});
|
2023-04-30 11:42:11 +00:00
|
|
|
}
|
|
|
|
|
2023-05-25 06:09:13 +00:00
|
|
|
onAfterUiUpdate(imageMaskResize);
|
2023-05-17 12:46:58 +00:00
|
|
|
window.addEventListener('resize', imageMaskResize);
|