Last active
October 11, 2022 19:00
-
-
Save ReiFan49/57183bae9f66eb7e3088ce6193795fbb to your computer and use it in GitHub Desktop.
Enable DevTools based download for StableDiffusion web-ui
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
// Stable Diffusion WebUI Javascript plugin | |
// Rei_Fan49 (c) 2022 | |
// MIT License. | |
window.addEventListener('DOMContentLoaded', function(){ | |
const sources = [ | |
'https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js', | |
'https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js', | |
]; | |
sources.forEach(function(src){ | |
const script = document.createElement('script'); | |
script.src = src; | |
document.body.appendChild(script); | |
}); | |
}); | |
function downloadAllImages(){ | |
const images = gradioApp().querySelectorAll('div:not(.grid) > button.gallery-item > img'); | |
const imageData = []; | |
const ctime = Math.floor((new Date()).getTime() / 1000); | |
images.forEach(function(imgElm){ | |
const data = {}; | |
data.img = imgElm.src.split(',').pop(); | |
const rawData = atob(data.img); | |
[ | |
['seed', /seed[:]\s(\d+)/i], | |
].forEach(function(_){ | |
const k = _[0]; | |
const gex = _[1]; | |
data[k] = gex.test(rawData) ? gex.exec(rawData)[1] : 'n'; | |
}); | |
imageData.push(data); | |
}); | |
const zipName = `${ctime}.zip`; | |
const zipData = new JSZip(); | |
const padSize = Math.max(4, String(imageData.length).length); | |
const padStr = function(data) { return '0'.repeat(Math.max(0, padSize - String(data).length)) + String(data); }; | |
imageData.forEach(function(data, index) { | |
const padIndex = padStr(index); | |
zipData.file( | |
`${ctime}.${padIndex}.${data.seed}.png`, | |
data.img, | |
{base64: true}, | |
); | |
}); | |
zipData.generateAsync({type: 'blob'}).then(content => saveAs(content, zipName)); | |
} |
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
// Stable Diffusion WebUI Javascript plugin | |
// Rei_Fan49 (c) 2022 | |
// MIT License. | |
window.addEventListener('DOMContentLoaded', function(){ const sources = [ 'https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js', 'https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js']; sources.forEach(function(src){ const script = document.createElement('script'); script.src = src; document.body.appendChild(script);});}); | |
function downloadAllImages(){ const images = gradioApp().querySelectorAll('div:not(.grid) > button.gallery-item > img'); const imageData = []; const ctime = Math.floor((new Date()).getTime() / 1000); images.forEach(function(imgElm){ const data = {}; data.img = imgElm.src.split(',').pop(); const rawData = atob(data.img); [['seed', /seed[:]\s(\d+)/i] ].forEach(function(_){ const k = _[0]; const gex = _[1]; data[k] = gex.test(rawData) ? gex.exec(rawData)[1] : 'n';});imageData.push(data);});const zipName = `${ctime}.zip`; const zipData = new JSZip(); const padSize = Math.max(4, String(imageData.length).length); const padStr = function(data) { return '0'.repeat(Math.max(0, padSize - String(data).length)) + String(data); }; imageData.forEach(function(data, index) { const padIndex = padStr(index); zipData.file( `${ctime}.${padIndex}.${data.seed}.png`, data.img, {base64: true});});zipData.generateAsync({type: 'blob'}).then(content => saveAs(content, zipName));} |
Author
ReiFan49
commented
Oct 11, 2022
- Revised from snippet only to pluggable javascript code.
- Put data seed into filename as well.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment