Created
April 18, 2023 23:25
-
-
Save MrCheatEugene/b0eb0f9c26174e98bf70c7a63db098d9 to your computer and use it in GitHub Desktop.
Конвертер webp в png для Windows, на PHP. Требует dwebp.exe и shell_exec.
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
<?php | |
// с линуксом не совместим:) меняйте обратные слэши на прямые | |
$dwebp="C:\\dwebp.exe";// путь к dwebp | |
$log=""; | |
if(isset($_GET['webpfolder']) && isset($_GET['pngfolder'])){ | |
header("Content-Type: application/json"); | |
if(!is_dir($_GET['webpfolder'])){ | |
die(json_encode(['success'=>false,'error'=>'Папка не существует, или нет прав'])); | |
} | |
if(!is_dir($_GET['webpfolder'].'\\'.$_GET['pngfolder']) and file_exists($_GET['webpfolder'].'\\'.$_GET['pngfolder'])==false){ | |
mkdir($_GET['webpfolder'].'\\'.$_GET['pngfolder']); | |
} | |
$i=0; | |
foreach(scandir($_GET['webpfolder']) as $file){ | |
if($file=='.' or $file=='..' or $file=='images'){ | |
continue; | |
} | |
$file=($_GET['webpfolder']).'\\'.$file; | |
$outfile=($_GET['webpfolder']).'\\'.$_GET['pngfolder'].'\\'.strval($i).'.png'; | |
$log.=shell_exec('\"'.$dwebp.'\" "'.$file.'" -o "'.$outfile.'"'); | |
$i+=1; | |
} | |
die(json_encode(['success'=>true,'error'=>'','log'=>$log])); | |
} | |
?> | |
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width, initial-scale=1"> | |
<title>Bootstrap demo</title> | |
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65" crossorigin="anonymous"> | |
</head> | |
<body> | |
<div class="container-fluid w-50 justify-content-center mt-3"> | |
<h1>webp2png</h1> | |
<h3 class="text-muted fst-italic">веб-версия</h3> | |
<hr> | |
<form id="form"> | |
<div class="mb-3"> | |
<label for="webpfolder" class="form-label">Папка с webp</label> | |
<input type="text" class="form-control" id="webpfolder" placeholder="Абсолютный путь, без кавычек"> | |
</div> | |
<div class="mb-3"> | |
<label for="pngfolder" class="form-label">Папка вывода PNG</label> | |
<input type="text" class="form-control" id="pngfolder" value="images" placeholder="Подпапка в папке с webp"> | |
</div> | |
<button type="submit" class="btn btn-primary">Отправить</button> | |
</form> | |
<script> | |
document.getElementById('form').onsubmit=async function(e){ | |
e.preventDefault(); | |
let res=await fetch(window.location.href+"?webpfolder="+encodeURIComponent(document.getElementById('webpfolder').value)+"&pngfolder="+encodeURIComponent(document.getElementById('pngfolder').value)); | |
res=await res.json(); | |
if(res['success']){ | |
alert("Успех!"); | |
}else{ | |
alert("Ошибка: "+res['error']); | |
} | |
} | |
</script> | |
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-kenU1KFdBIe4zVF0s0G1M5b4hcpxyD9F7jL+jjXkk+Q2h455rYXK/7HAuoJl+0I4" crossorigin="anonymous"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment