Add compression estimates, transparent image output and full format selection
This commit is contained in:
1 parent
65cebb31ca
commit
2b897267d1
22 files changed
+220
-30
No files matched your search
@@ -20,9 +20,27 @@ async function init(){
|
||||
$('#filename').textContent=items.length===1?items[0].name:`${items.length} Dateien`;
|
||||
const content=$('#content');
|
||||
if(config.type==='compress'){
|
||||
$('#title').textContent='Komprimieren';content.append(text('Bilder werden als JPEG, Videos als MP4 und Audio als MP3 gespeichert. PDFs behalten ihr Format.'));
|
||||
$('#title').textContent='Komprimieren';content.append(text('PNG, WebP und AVIF behalten ihr Format. Andere Bilder werden als JPEG gespeichert, bei Transparenz als PNG. Videos werden MP4, Audio MP3. PDFs behalten ihr Format.'));
|
||||
const q=field('Qualität: 75 %','quality','range',75);q.lastChild.min=5;q.lastChild.max=95;q.lastChild.oninput=e=>q.firstChild.textContent=`Qualität: ${e.target.value} %`;content.append(q,field('Maximale Größe pro Datei (MB, optional)','maxSizeMB','number',''));
|
||||
$('#maxSizeMB').step='.1';content.append(text('Eine Zielgröße ist bei manchen Dateien nicht erreichbar. Das Ergebnis wird dann entsprechend gekennzeichnet.'));
|
||||
content.append(text('PNG wird verlustfrei optimiert. Eine kleinere Zielgröße kann die Bildabmessungen verringern.'));
|
||||
const estimate=text('Größe wird berechnet …');estimate.id='estimate';estimate.setAttribute('aria-live','polite');content.append(estimate);
|
||||
if(items.length>1)content.append(text(`Die Prognose bezieht sich auf ${items[0].name}. Die Einstellungen gelten für alle ausgewählten Dateien.`));
|
||||
let timer, revision=0;
|
||||
const bytes=value=>value<1024*1024?`${(value/1024).toLocaleString('de-DE',{maximumFractionDigits:1})} KB`:`${(value/1024/1024).toLocaleString('de-DE',{maximumFractionDigits:2})} MB`;
|
||||
const update=()=>{const current=++revision;clearTimeout(timer);estimate.textContent='Größe wird berechnet …';timer=setTimeout(async()=>{try{
|
||||
const result=await api.estimate({quality:Number($('#quality').value),maxSizeMB:Number($('#maxSizeMB').value)});
|
||||
if(current!==revision||!result)return;
|
||||
const change=result.originalSize?Math.round((1-result.size/result.originalSize)*100):0;
|
||||
estimate.textContent=`${result.exact?'Voraussichtliche Größe':'Geschätzte Größe'}: ${bytes(result.size)} (${result.format.toUpperCase()}) · ${change>=0?`${change} % kleiner`:`${-change} % größer`} als ${bytes(result.originalSize)}${result.targetMet?'':' · Zielgröße voraussichtlich nicht erreichbar'}`;
|
||||
}catch(e){if(current===revision)estimate.textContent=`Keine Prognose verfügbar: ${e.message}`;}},500);};
|
||||
$('#quality').addEventListener('input',update);$('#maxSizeMB').addEventListener('input',update);update();
|
||||
}else if(config.type==='format'){
|
||||
$('#title').textContent='Bildformat wählen';
|
||||
const row=document.createElement('label');row.className='field';row.append(document.createTextNode('Ausgabeformat'));
|
||||
const select=document.createElement('select');select.id='format';
|
||||
for(const fmt of ['jpg','png','webp','gif','avif','tiff','ico','bmp','heic','heif','pdf']){const option=document.createElement('option');option.value=fmt;option.textContent=fmt.toUpperCase();select.append(option);}
|
||||
row.append(select);content.append(row);
|
||||
}else if(config.type==='password'){
|
||||
$('#title').textContent=config.mode==='add'?'PDF mit Passwort schützen':'PDF-Passwort entfernen';
|
||||
content.append(field(config.mode==='add'?'Neues Passwort':'Aktuelles Passwort','password','password'));
|
||||
@@ -45,7 +63,7 @@ async function init(){
|
||||
$('#save').disabled=false;
|
||||
}catch(e){error(e.message);}
|
||||
}
|
||||
if(config.type!=='combine'&&config.type!=='password')content.append(field('Dateiname (optional, ohne Endung)','outputName','text'));
|
||||
if(!['combine','password','format'].includes(config.type))content.append(field('Dateiname (optional, ohne Endung)','outputName','text'));
|
||||
}
|
||||
$('#cancel').onclick=()=>api.submit(null);
|
||||
$('#save').onclick=()=>{
|
||||
@@ -53,6 +71,7 @@ $('#save').onclick=()=>{
|
||||
const invalid=[...document.querySelectorAll('input')].find(input=>!input.checkValidity());if(invalid){invalid.reportValidity();return;}
|
||||
if(config.type==='password'){const password=$('#password').value;if(!password)return error('Bitte ein Passwort eingeben.');if(config.mode==='add'&&password!==$('#confirm').value)return error('Die Passwörter stimmen nicht überein.');return api.submit(password);}
|
||||
if(config.type==='combine')return api.submit({files:items.map(x=>x.path),format:$('#format').value});
|
||||
if(config.type==='format')return api.submit($('#format').value);
|
||||
const result={};for(const id of ['quality','maxSizeMB','width','height','rotate','time']){if($('#'+id)&&$('#'+id).value!=='')result[id]=Number($('#'+id).value);}
|
||||
for(const id of ['flipH','flipV'])if($('#'+id))result[id]=$('#'+id).checked;
|
||||
if(config.type==='edit'&&config.mode==='crop'){if(!crop||crop.width<2||crop.height<2)return error('Bitte einen Bildbereich auswählen.');result.crop=crop;}
|
||||
|
||||
Reference in new issue
Block a user