GPT4 帮我实现 Mac 图片自动压缩上传 COS

2023-06-04 08:58:45 +08:00
 xuelang

把个人博客放在了 netilfy 托管,它给了一个优化建议,可以压缩图片节省带宽。但是每次截图后都要再压缩下图片有点麻烦,于是想着应该可以偷偷懒。目标很明确,截图后图片传到我的 git 仓库 images 目录后,能给我自动压缩,并且上传 COS ,这样我就只用在 markdown 文件里面拼链接就好了。

脚本

on run {input, parameters}
	set currentDate to do shell script "date '+%Y%m%d'"
	tell application "System Events"
		repeat with i in input
			set filePath to POSIX path of i
			set fileExtension to name extension of i
			set folderName to do shell script "dirname " & filePath
			if fileExtension is "png" then
				set fileName to name of i
				set AppleScript's text item delimiters to "."
				set baseName to first text item of fileName
				if baseName does not start with currentDate then
					do shell script "/opt/homebrew/bin/pngquant --force --ext .png " & quoted form of filePath
					set newBaseName to currentDate & "_" & baseName
					set newFileName to newBaseName & "." & fileExtension
					set name of i to newFileName
					set newFilePath to folderName & "/" & newFileName
					set uploadCommand to "/opt/homebrew/Caskroom/miniconda/base/bin/coscmd upload " & quoted form of newFilePath & " /"
					do shell script uploadCommand
				end if
			end if
		end repeat
	end tell
end run

完整内容

1091 次点击
所在节点    OpenAI
1 条回复
xuelang
2023-06-04 09:03:12 +08:00
V2ex 请求 cos 图片,为啥不带 referer ,这里防盗链白名单加了也没用

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/945601

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX