functionfig{param([string]$id,[int]$Fuzz1=2,[int]$Fuzz2=2)$current_dir=Get-Location$snip_dir="C:\Users\wenzexu\Pictures\Screenshots"$latest_file=Get-ChildItem-Path$snip_dir|Sort-ObjectLastWriteTime-Descending|Select-Object-First1if($latest_file){$md5_hash=(Get-FileHash-Path$latest_file.FullName-AlgorithmMD5).Hash.ToLower()$extension=$latest_file.Extension.TrimStart(".").ToLower()if($extension-in@("jpg","jpeg","png")){$extension="webp"$new_name="$md5_hash.$extension"$new_path=Join-Path$snip_dir$new_namemagick"$($latest_file.FullName)"-quality100-definewebp:lossless=true-fuzz"$Fuzz1%"-fillwhite-opaquewhite"$new_path"}else{if($latest_file.Name-ne$extension){$new_name="$md5_hash.$extension"}else{$new_name="$md5_hash"}$new_path=Join-Path$snip_dir$new_nameRename-Item-Path$latest_file.FullName-NewName$new_name}$original_url="https://img.ricolxwz.io/$new_name"$inverted_name="${md5_hash}_inverted.$extension"$inverted_url="https://img.ricolxwz.io/$inverted_name"$inverted_path=Join-Path$snip_dir$inverted_namemagick"$new_path"-negate`-fuzz"$Fuzz2%"-fill"rgb(18,19,23)"-opaqueblack`-fuzz"$Fuzz2%"-fill"rgb(226,228,233)"-opaquewhite`-quality100`"$inverted_path"Write-Output"Processed image: $new_name"# $upload_choice = Read-Host "Do you want to perform the upload operation? (Default no, enter y to proceed) [y/N]"$upload_choice="y"if($upload_choice-match'^[Yy]$'-or$upload_choice-eq''){Write-Output"Starting upload operation..."try{# aws s3 cp "$new_path" "s3://ricolxwz-image/" --profile image# aws s3 cp "$inverted_path" "s3://ricolxwz-image/" --profile imagewranglerr2objectput"ricolxwz-image/$new_name"--file"$new_path"wranglerr2objectput"ricolxwz-image/$inverted_name"--file"$inverted_path"Write-Output"All upload operations completed."$figid="fig$id"$capid="图${id}: "$text=@"<figure markdown='1' id='$figid'>#only-light){ loading=lazy width='800' }#only-dark){ loading=lazy width='800' }<figcaption>$capid</figcaption></figure>"@$text|Set-ClipboardWrite-Output"The formatted text has been copied to the clipboard. Please paste to save."}catch{Write-Error"An error occurred during upload: $_"return}# $rollback_choice = Read-Host "Do you want to perform rollback operation? (Default no, enter y to proceed) [y/N]"$rollback_choice="n"if($rollback_choice-match'^[Yy]$'){Write-Output"Starting rollback operation..."functionRollback($file_name){try{# aws s3 rm "s3://ricolxwz-image/$file_name" --profile imagewranglerr2objectdelete"ricolxwz-image/$file_name"}catch{Write-Error"An error occurred while rolling back ${file_name}: $_"}}Rollback$new_nameRollback$inverted_nameWrite-Output"Rollback operation completed."}else{Write-Output"Rollback operation not performed."}}else{Write-Output"Upload operation not performed."}Set-Location$current_dir}else{Write-Host"No files found."}}