使用Unsplash API和Shortcut为IPhone定时更换壁纸
Posted
今年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:
Authorization: Client-ID YOUR_ACCESS_KEY
You can also pass this value using a client_id
query parameter:
https://api.unsplash.com/photos/?client_id=YOUR_ACCESS_KEY
Get a random photo
Retrieve a single random photo, given optional filters.
GET /photos/random
API获取图片链接
#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 theixid
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 photocrop
: for applying cropping to the photofm
: for converting image formatauto=format
: for automatically choosing the optimal image format depending on user browserq
: for changing the compression quality when using lossy file formatsfit
: for changing the fit of the image within the specified dimensionsdpr
: for adjusting the device pixel ratio of the image
#例如想要匹配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
②全部打钩
③为Application设置一个名称
④复制Access Key
至此取得Access Key
Shortcut快捷指令设置
可以使用或参考我分享的Shortcut,在YOUR_ACCESS_KEY
填入前面复制的KEY。
在Shortcut自动化中添加定时启动这个捷径。
关闭运行前询问,运行更无感。
效果演示
该演示为全程锁屏状态下