作者 yuzuki ()標題 [心得] 用Cloud flare Worker AI 隨機畫桌布時間 Fri Feb 13 01:54:39 2026
一時興起,搞了一個多禮拜的實驗
事情是這樣,最近發現三星手機有AI繪製桌布和AI天氣效果的功能,但實際用了之後還是覺
但我要的是可以根據現在天氣隨機繪製一張,而且會定時更新
研究了一下發現利用API繪圖應該是可行的辦法,但大部分API都要錢,如果一小時畫一張一
後來就注意到cloudflar有每天免費額度,對於我這種需求正好,但實際執行還是費了不少?
我會分享範例文件,歡迎各位指教
https://drive.google.com/drive/folders/1CW5EzsOymc8rPa-wCrtKuGS29z9HPmV1
需要申請:
Cloudflare 帳號
openweathermap 帳號
A.cloudflare 帳號
這目標是拿到帳號ID和AI token
帳號ID是my dashbord的網址中
https://dash.cloudflare.com/ 帳號ID /home/domains
token大概用下面方式取得
https://i.meee.com.tw/82Z4f5W.jpg
https://i.meee.com.tw/O65Zgzx.jpg
https://i.meee.com.tw/OwpWFLS.jpg
https://i.meee.com.tw/z4sqPcD.jpg
https://i.meee.com.tw/hB4g7Oi.jpg
2.openweathermap
目標是拿到API
大概像這樣
https://i.meee.com.tw/BHghsP5.jpg
B.關鍵字繪圖
這裡準備了一個python腳本,其中關鍵字產生長這樣
https://i.meee.com.tw/SUBkw28.png
原理是先利用現代位置傳給API,API回傳現在天氣,日出日落時間
然後根據不同天氣,從一大串關鍵字中選幾個,加上天氣描述和日夜描述,當作繪圖的基底
當然有這些關鍵字就能畫圖,但我決定複雜點,將剛才的關鍵字扔進LLM模型,請AI模型幫?
https://i.meee.com.tw/ZRGU8s4.png
產生關鍵字的promt可以自行修改,但我建議留著promt only等補述,否則LLM會產生諸如"?
擴展的關鍵字可以傳入繪圖AI,也可以加入negative promt。
其中最重要的一步是決定影像大小
這裡有所限制,影像的寬高需要是256的倍數,最大是2048,建議從中選一個最接近螢幕長?
https://i.meee.com.tw/fveTaFV.png
然後回傳的影像經由PIL套件存檔
C.設定termux
temux是個終端機,我屆此在手機上執行python
在此須安裝
Termux
Termux-API
不建議安裝play版,我是在FDROID上裝,或是在git上裝,但兩者來源需相同
安裝好兩者之後要安裝套件,在termux鍵入
pkg update && upgrade
pkg install termux-api
pkg install jq
pkg install python
pkg install libjpeg-turbo
pkg install libpng
pip install pillow
pip install requests
termux-storage-setup 然後給予termux存取檔案權限
ternux-location 這時候會跳出給termux-api 位置權限,記得要選"永遠允許"而非"應用程
再試一次
termux-location -r last 這時應該要跳出目前位置
安裝好後我們把範例檔中的 api.json AI_wallpaper.py AI_wallpaper.sh放入Pictures底?
api.json裡要填入剛才申請到的token和API
然後termux鍵入
mkdir ~/AI_wallpaper/
cp /storage/emulated/0/Pictures/AI_wallpaper/AI_wallpaper.sh ~/AI_wallpaper/
chmod +x ~/AI_wallpaper/AI_wallpaper.sh
上面三步是創建資料夾,把AI_wallpaper.sh搬過去,給予執行權限
現在可以執行看看 ~/AI_wallpaper/AI_wallpaper.sh
應該可以順利看到產生一張圖和一個log在 Picture/AI_wallpaper資料夾並被設定成桌面
如果可以執行,那鍵入
termux-job-scheduler \
--script /data/data/com.termux/files/home/AI_wallpaper/AI_wallpaper.sh \
--period-ms 3600000 \
--persisted true \
--battery-not-low true
這樣就可以設定定期一小時執行
D.摺疊機
個人是用折疊機,但上述程序有點麻煩,因為系統只讓我設定現在這個螢幕的桌布,不能設
這裡利用
termux-sensor -s "hinge_angle Wakeup" -n 1
找到一個叫做"hinge_angle Wakeup"感測器,這個感測器折起來時輸出0,反之為180,我?
我把範例檔附上,但我不敢保這這個感測器的名稱在其他摺疊機能不能用
E.結果
keywords: railway, lake, mountain, ocean, Dusk, clear sky
Prompt: A railway track winds its way along the shores of a serene lake, surroun
by towering mountains that reflect perfectly in the calm waters at dusk. In
the distance, the ocean stretches out to the horizon, where the sky is
painted with hues of pink and orange, gradating into a brilliant blue. The
atmosphere is tranquil, with a few wispy clouds scattered across the clear
sky, adding a touch of softness to the scene.
https://i.meee.com.tw/XgIsnFA.jpg https://i.meee.com.tw/5rpbIxV.jpg
keywords: city, island, coastline, outdoor, Dusk, clear sky
Prompt: A serene coastal cityscape at dusk, with the sun dipping into the horizo
casting a warm orange glow across the tranquil waters of the ocean. The sky
above is a brilliant blue, with a few wispy clouds scattered across the
canvas, their silhouettes outlined against the vibrant hues of the setting
sun. The city's skyline is a blend of modern and vintage architecture, with
sleek skyscrapers and charming beachside bungalows, all bathed in the soft
golden light of dusk. The coastline is dotted with elegant lamp posts, their
soft glow illuminating the winding promenade that stretches along the shore.
In the distance, the outline of a small island can be seen, its rugged
silhouette a striking contrast to the calm waters. The atmosphere is
peaceful, with the sound of gentle waves and the distant hum of city life
providing a soothing background melody.
https://i.meee.com.tw/xlzeuD5.jpg https://i.meee.com.tw/eWphWcs.jpg
keyword: coastline, island, city, ocean, Night, clear sky
the distance, the ocean stretches out to the horizon, where the sky is
painted with hues of pink and orange, gradating into a brilliant blue. The
atmosphere is tranquil, with a few wispy clouds scattered across the clear
sky, adding a touch of softness to the scene.
https://i.meee.com.tw/XgIsnFA.jpg https://i.meee.com.tw/5rpbIxV.jpg
keywords: city, island, coastline, outdoor, Dusk, clear sky
Prompt: A serene coastal cityscape at dusk, with the sun dipping into the horizo
casting a warm orange glow across the tranquil waters of the ocean. The sky
above is a brilliant blue, with a few wispy clouds scattered across the
canvas, their silhouettes outlined against the vibrant hues of the setting
sun. The city's skyline is a blend of modern and vintage architecture, with
sleek skyscrapers and charming beachside bungalows, all bathed in the soft
golden light of dusk. The coastline is dotted with elegant lamp posts, their
soft glow illuminating the winding promenade that stretches along the shore.
In the distance, the outline of a small island can be seen, its rugged
silhouette a striking contrast to the calm waters. The atmosphere is
peaceful, with the sound of gentle waves and the distant hum of city life
providing a soothing background melody.
https://i.meee.com.tw/xlzeuD5.jpg https://i.meee.com.tw/eWphWcs.jpg
keyword: coastline, island, city, ocean, Night, clear sky
Prompt: A serene coastal city on a tropical island at night, with a crystal-clea
displaying a million twinkling stars. The city's skyline is dominated by a
majestic lighthouse standing tall on a rocky outcropping, its beam cutting
through the darkness. In the distance, the ocean waves gently lap against the
shore, creating a soothing melody. The city's buildings are a mix of modern
and colonial architecture, with brightly lit windows and streets bustling
with nocturnal activity. A few sailboats are moored in the harbor, their
sails billowing in the gentle breeze. The air is filled with the sweet scent
of blooming flowers and the distant tang of saltwater, as the city's
residents go about their evening routines under the celestial showcase above.
https://i.meee.com.tw/3ws362Q.jpg https://i.meee.com.tw/QBJcpx2.jpg
橫屏狀況
keyword: outdoor, ocean, railway, traffic, Night, clear sky
Prompt: A serene night scene of a coastal railway track overlooking the vast oce
with no traffic in sight. The clear sky above is filled with a million
twinkling stars, and the only sound is the distant hum of a passenger train
making its way along the tracks, its lights casting a warm glow on the dark
sand below.
https://i.meee.com.tw/fmWbnzU.jpg
https://i.meee.com.tw/ad504DJ.jpg
心得和建議:
1. 整個python程式因為有AI幫忙,算是單純很多,但就是搞termux和android權限等等搞了
2. Stable deffusion模型在細節上差強人意,如果要更好的細節,cloudflare有提供lucid
3. Stable deffusion有時也會產生很多不合理的東西,樹讓的人,水裡的車,斷掉路和鐵?
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 36.228.93.245 (臺灣)
※ 作者: yuzuki 2026-02-13 01:54:39
※ 文章代碼(AID): #1fZXFcCO (MobileComm)
※ 文章網址: https://www.ptt.cc/bbs/MobileComm/M.1770918886.A.318.html
推 ec97: 懶得看先推2F 02/13 04:04
推 phoque: 懶人包:iPhone不行6F 02/13 08:19
推 iscool: 看不懂XD但是推詳細教學8F 02/13 09:40
不敢不敢,只算是筆記,整個程序的穩健性不夠好,資料還亂丟
※ 編輯: yuzuki (42.73.228.32 臺灣), 02/13/2026 11:10:44
推 lemondog: 其實開源就好,技術棧和代碼圖看的少12F 02/13 11:36
→ korsg: 讚喔13F 02/13 11:52
推 daae: 好的 看不懂14F 02/13 12:14
推 sdbb: 謝謝,新年快樂15F 02/13 12:27
推 issemn: 看不懂 但我要桌布’’,,,17F 02/13 13:20
推 boringuser: ? iPhone用捷徑絕對可以達成啊 可能還比安卓簡單18F 02/13 13:28
噓 phoque: iPhone不能用這篇的方法啊 誰在跟你簡單不簡單20F 02/13 14:35
--