Featured image of post 使用Unsplash API和Shortcut为IPhone定时更换壁纸

使用Unsplash API和Shortcut为IPhone定时更换壁纸

减少IPhone14Pro系列熄屏显示功能所引发的烧屏风险。

今年IPhone 14 Pro 系列增加了Apple Watch的熄屏显示(Always On Display)功能。这个功能真的很香,大约每小时多消耗1%的电量,同时在无光环境下(如放口袋里、夜晚关灯后)屏幕会自动熄灭。当然我相信苹果肯定做了系统优化防止OLED烧屏,至少过保前肯定不会烧是吧。

Unsplash API

API简介

Authorization

Public Authentication

Most actions can be performed without requiring authentication from a specific user. For example, searching, fetching, or downloading a photo does not require a user to log in.

To authenticate requests in this way, pass your application’s access key via the HTTP Authorization header:

1
Authorization: Client-ID YOUR_ACCESS_KEY

You can also pass this value using a client_id query parameter:

1
https://api.unsplash.com/photos/?client_id=YOUR_ACCESS_KEY

Get a random photo

Retrieve a single random photo, given optional filters.

1
GET /photos/random

API获取图片链接

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
#YOUR_ACCESS_KEY  Application Access Key
#/photos/random 为获得随机的图片
#orientation=portrait 图片风格竖屏、横屏等(Valid values: landscape, portrait, squarish)
#query=wallpapers 搜索图片类型


curl https://api.unsplash.com/photos/random?client_id=YOUR_ACCESS_KEY&orientation=portrait&query=wallpapers

#返回内容中含有图片链接词典
"urls":{"raw":"https://images.unsplash.com/photo-1499262222376-d10eb3d5183f?ixid=MnwzNjY2MTl8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NjQwNzMxODQ&ixlib=rb-1.2.1","full":"https://images.unsplash.com/photo-1499262222376-d10eb3d5183f?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzNjY2MTl8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NjQwNzMxODQ&ixlib=rb-1.2.1&q=80","regular":"https://images.unsplash.com/photo-1499262222376-d10eb3d5183f?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwzNjY2MTl8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NjQwNzMxODQ&ixlib=rb-1.2.1&q=80&w=1080","small":"https://images.unsplash.com/photo-1499262222376-d10eb3d5183f?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwzNjY2MTl8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NjQwNzMxODQ&ixlib=rb-1.2.1&q=80&w=400","thumb":"https://images.unsplash.com/photo-1499262222376-d10eb3d5183f?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=MnwzNjY2MTl8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NjQwNzMxODQ&ixlib=rb-1.2.1&q=80&w=200","small_s3":"https://s3.us-west-2.amazonaws.com/images.unsplash.com/small/photo-1499262222376-d10eb3d5183f"}

这里有几种类型的图片raw full regular small thumb small_s3 ,对应的键值为该质量图片的下载链接。

  • full returns the photo in jpg format with its maximum dimensions. For performance purposes, we don’t recommend using this as the photos will load slowly for your users.
  • regular returns the photo in jpg format with a width of 1080 pixels.
  • small returns the photo in jpg format with a width of 400 pixels.
  • thumb returns the photo in jpg format with a width of 200 pixels.
  • raw returns a base image URL with just the photo path and the ixid parameter for your API application. Use this to easily add additional image parameters to construct your own image URL.

同时可以通过以下参数调整图像大小质量

  • w, h: for adjusting the width and height of a photo
  • crop: for applying cropping to the photo
  • fm: for converting image format
  • auto=format: for automatically choosing the optimal image format depending on user browser
  • q: for changing the compression quality when using lossy file formats
  • fit: for changing the fit of the image within the specified dimensions
  • dpr: for adjusting the device pixel ratio of the image
1
2
#例如想要匹配IPhone宽度1290
https://images.unsplash.com/photo-1499262222376-d10eb3d5183f?crop=entropy&cs=tinysrgb&fm=jpg&ixid=MnwzNjY2MTl8MHwxfHJhbmRvbXx8fHx8fHx8fDE2NjQwNzMxODQ&ixlib=rb-1.2.1&q=80&w=1290

下面是配置步骤

注册一个账号

创建一个Application,获取Access Key

①创建Application

unsplash-new-application

②全部打钩

unsplash-accesskey-step02

③为Application设置一个名称

unsplash-accesskey-step03

复制Access Key

unsplash-accesskey-step04

至此取得Access Key

Shortcut快捷指令设置

可以使用或参考我分享的Shortcut,在YOUR_ACCESS_KEY填入前面复制的KEY。

shortcut_config

在Shortcut自动化中添加定时启动这个捷径。

shortcut_autoconfig01

关闭运行前询问,运行更无感。

shortcut_autoconfig02

shortcut_autoconfig03

效果演示

该演示为全程锁屏状态下

1

 




参考

  1. 使用 Shortcut 自动更换 Unsplash 的壁纸
  2. Change the wallpaper with unsplash API by using Shortcuts
  3. Unsplash API Documentation