在线转化
<!DOCTYPE html><html>
<head>
<title>WebP转JPG</title>
</head>
<body>
<h1>WebP转JPG</h1>
<form action="convert.php" method="post" enctype="multipart/form-data">
<label for="file">选择要转换的文件:</label>
<input type="file" name="file" id="file"><br><br>
<input type="submit" name="submit" value="转换">
</form>
</body>
</html>
<?php
if(isset($_POST["submit"])) {
$target_dir = "/converted/";
$target_file = $target_dir . basename($_FILES["file"]["name"]);
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// 检查文件是否为WebP格式
if($imageFileType != "webp") {
echo "只能转换WebP格式的图片。";
exit;
}
// 转换图片格式
$image = imagecreatefromwebp($_FILES["file"]["tmp_name"]);
$jpg_file = $target_dir . pathinfo($target_file, PATHINFO_FILENAME) . ".jpg";
imagejpeg($image, $jpg_file, 100);
imagedestroy($image);
// 显示转换后的图片
echo "<h2>转换后的图片:</h2>";
echo "<img src='$jpg_file'>";
}
?>
页:
[1]