• Welcome to LiuJason's Blog!

Windows下用脚本一键批量转换HEIC为JPEG

AI Jason 1 minutes ago 2 Views 0 Comments QR code of this page

用DeepSeek写了个脚本,超级方便。

使用前需要安装 https://imagemagick.org/script/download.php

# HEIC to JPEG Conversion Script

# Check if ImageMagick is installed (required for HEIC conversion)
if (-not (Get-Command magick -ErrorAction SilentlyContinue)) {
    Write-Host "ImageMagick is required for HEIC conversion. Please install it first." -ForegroundColor Red
    Write-Host "You can install it via Chocolatey: 'choco install imagemagick'" -ForegroundColor Yellow
    exit 1
}

# Create 'converted' directory if it doesn't exist
$convertedDir = Join-Path -Path $PWD.Path -ChildPath "converted"
if (-not (Test-Path -Path $convertedDir)) {
    New-Item -ItemType Directory -Path $convertedDir | Out-Null
}

# Get all HEIC files in current directory
$heicFiles = Get-ChildItem -Filter *.HEIC

if ($heicFiles.Count -eq 0) {
    Write-Host "No HEIC files found in the current directory." -ForegroundColor Yellow
    exit 0
}

# Convert each HEIC file to JPEG
foreach ($file in $heicFiles) {
    $jpegName = [System.IO.Path]::ChangeExtension($file.Name, "jpeg")
    $jpegPath = Join-Path -Path $PWD.Path -ChildPath $jpegName
    
    Write-Host "Converting $($file.Name) to $jpegName..." -ForegroundColor Cyan
    
    # Convert using ImageMagick
    magick $file.FullName $jpegPath
    
    if ($LASTEXITCODE -eq 0) {
        # Move original HEIC to converted folder
        $destination = Join-Path -Path $convertedDir -ChildPath $file.Name
        Move-Item -Path $file.FullName -Destination $destination -Force
        Write-Host "Conversion successful. Moved original to converted folder." -ForegroundColor Green
    } else {
        Write-Host "Conversion failed for $($file.Name)" -ForegroundColor Red
    }
}

Write-Host "`nConversion process completed." -ForegroundColor Green
Write-Host "Converted $($heicFiles.Count) HEIC files to JPEG." -ForegroundColor Green

This article is under CC BY-NC-SA 4.0 license.
Please quote the original link:https://www.liujason.com/article/1299.html
Like (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址