【组件】前端js HEIC/HEIF 转换为JPEG、PNG或GIF格式 苹果格式

【组件】前端js HEIC/HEIF 转换为JPEG、PNG或GIF格式

Heic2any: Client-side conversion of HEIC/HEIF image files to JPEG,PNG, or GIF in the browser.icon-default.png?t=O83Ahttps://alexcorvi.github.io/heic2any/#demo

GitHub - alexcorvi/heic2any: Converting HEIF/HEIF image formats to PNG/GIF/JPEG in the browser

Demo

Heic2any: Client-side conversion of HEIC/HEIF image files to JPEG,PNG, or GIF in the browser.

引入的js可以从这里下载到本地

https://download.csdn.net/download/G971005287W/89916148

代码  直接保存成html 本地运行即可看到效果

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>HEIC to PNG Conversion</title>
    <script src="https://cdn.jsdelivr.net/npm/heic2any"></script>
</head>
<body>
    <h2>Upload HEIC Image and Convert to PNG</h2>
    <input type="file" id="heicInput" accept="image/heic" />
    <br><br>
    <div id="previewContainer">
        <h3>Converted Image Preview:</h3>
        <img id="preview" style="max-width: 100%; height: auto;" />
    </div>

    <script>
        document.getElementById('heicInput').addEventListener('change', function (event) {
            const file = event.target.files[0];
            if (!file) return;

            // 使用 FileReader 读取 HEIC 文件
            const reader = new FileReader();
            reader.onload = function (e) {
                const heicBlob = e.target.result;
                // 使用 heic2any 将 HEIC 转换为 PNG
                heic2any({
                    blob: new Blob([heicBlob], { type: 'image/heic' }),
                    toType: "image/png"
                }).then(function (resultBlob) {
                    // 生成图片的 URL 并展示预览
                    const previewImg = document.getElementById('preview');
                    const url = URL.createObjectURL(resultBlob);
                    previewImg.src = url;
                }).catch(function (error) {
                    console.error("Error converting HEIC to PNG:", error);
                });
            };

            // 以二进制格式读取 HEIC 文件
            reader.readAsArrayBuffer(file);
        });
    </script>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我是Superman丶

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值