banner
Tenifs

Tenifs

雄关漫道真如铁,而今迈步从头越。
github
follow
zhihu
email

💕 獲取一張二次元圖片

Are you still worried about the cover image? With this script, you can automatically download images and achieve freedom in choosing cover images.

Code Implementation#

echo "---- Fetch Image ----"
# Current time
$t = Get-Date -Format "yyyy_MM_dd_HH_mm_ss"
# Anime picture API
$uri = "https://t.alcy.cc/pc/"
# File name
$filename = $t + ".webp"
echo $filename
Invoke-WebRequest -Uri $uri -Outfile $filename
echo "---- Fetch Image ----"

How to Use#

Write the above code into a ps1 file. Whenever you want to get an image, simply run the script file using PowerShell.

image

2024-07-28: Adding Image Compression Functionality#

The new code is as follows:

# Get an anime picture
Write-Output "---- Fetch Image ----"
# Current time
$t = Get-Date -Format "yyyy_MM_dd_HH_mm_ss"
# Anime picture API
$uri = "https://t.alcy.cc/pc/"
# File name
$filename = $t + ".webp"
Write-Output "filename: $filename"
# Download
Invoke-WebRequest -Uri $uri -Outfile $filename
# Compress the image (quality q=5)
$input = $filename
$output = $t + "_compressed.webp"
ffmpeg -i $input -q 5 $output
# Delete the original image
Remove-Item $filename
Write-Output "---- Fetch Image ----"

Note: Image compression requires ffmpeg. Before running the script, please make sure that ffmpeg is installed and the environment variables are properly configured.

載入中......
此文章數據所有權由區塊鏈加密技術和智能合約保障僅歸創作者所有。