#tips こちらのWEBP画像変換機能 ですが、変換後のWEBP画像がちょっと荒いなと思ったのでChatGPTに聞いてカスタムしました。imagewebp関数で $qualityを渡すといいらしい。ついでにリヴリーのレイアウトいろいろ追加 したよ〜 忘備録として以下メモしておきます。▼MORE変更箇所// WebP変換function convertToWebp($filePath, $uploadDir, $fileExtension, $quality = 90) { $webpPath = $uploadDir . pathinfo($filePath, PATHINFO_FILENAME) . '.webp'; $image = null; switch ($fileExtension) { case 'jpg': case 'jpeg': $image = imagecreatefromjpeg($filePath); break; case 'png': $image = imagecreatefrompng($filePath); break; case 'gif': $image = imagecreatefromgif($filePath); break; } if ($image) { imagewebp($image, $webpPath, $quality); imagedestroy($image); unlink($filePath); } return $webpPath;}function convertThumbnailToWebp($thumbnailPath, $miniDir, $quality = 90) { $fileExtension = strtolower(pathinfo($thumbnailPath, PATHINFO_EXTENSION)); $webpThumbnailPath = $miniDir . pathinfo($thumbnailPath, PATHINFO_FILENAME) . '.webp'; switch ($fileExtension) { case 'jpg': case 'jpeg': $image = imagecreatefromjpeg($thumbnailPath); break; case 'png': $image = imagecreatefrompng($thumbnailPath); break; case 'gif': $image = imagecreatefromgif($thumbnailPath); break; case 'webp': $image = imagecreatefromwebp($thumbnailPath); break; default: $image = false; break; } if ($image !== false) { imagewebp($image, $webpThumbnailPath, $quality); imagedestroy($image); unlink($thumbnailPath); } else { echo "サムネイルの WebP 変換に失敗しました。対応していない画像形式か、ファイルが破損している可能性があります。"; }}▲CLOSE 2025/01/19 Site
こちらのWEBP画像変換機能 ですが、変換後のWEBP画像がちょっと荒いなと思ったのでChatGPTに聞いてカスタムしました。
imagewebp関数で $qualityを渡すといいらしい。ついでにリヴリーのレイアウトいろいろ追加 したよ〜 忘備録として以下メモしておきます。
変更箇所
▲CLOSE