Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

图片操作记录 #322

Open
toFrankie opened this issue Nov 10, 2023 · 0 comments
Open

图片操作记录 #322

toFrankie opened this issue Nov 10, 2023 · 0 comments
Labels
2023 2023 年撰写 生活随笔 一些杂七杂八的文章

Comments

@toFrankie
Copy link
Owner

toFrankie commented Nov 10, 2023

配图源自 Freepik

常用工具

它们的命令行工具均可通过 Homebrew 安装,部分有桌面客户端应用。

查看 GIF 信息

Gifsicle

# 查看所有帧信息
$ gifsicle --info source.gif
 
# 查看某帧信息
$ gifsicle --info "#0" "#3" < source.gif
 
# 查看详细颜色表
$ gifsicle --cinfo source.gif

支持网络图片

详见 get_info.sh,它内部依赖 ImageMagick。

$ gifinfo [-n number_of_frames] <filename>

其中 filename 支持网络图片。

GIF 转换为 PNG

使用 ImageMagick

# 逐帧导出
$ convert source.gif target.png

如果 GIF 已经过透明度处理(即第一帧信息完整保留,后续帧仅保留变化的部分,未变的空间均为透明),可通过 Gifsicle 还原,再使用 ImageMagick 处理。

# 还原
$ gifsicle --unoptimize source.gif > tmp.gif

# 逐帧导出
$ convert tmp.gif target.png

导出某帧

$ convert 'source.gif[0]' target.png

导出多帧,可以这样指定:source.gif[0-3]source.gif[3,2,4](非连续帧)。

GIF 帧操作

简单抽帧

使用 macOS 内置的「预览」应用,可以快速插入/删除帧。打开 GIF 并在「菜单栏 - 显示」切换为「缩略清单」。

  • 删除帧:选中帧后,使用「⌘ + delete」快捷键删除。
  • 添加帧:打开两组 GIF(必需都是 GIF),选中某帧,拖拽至另一个 GIF 对应帧的位置。比如,从 A 中拖拽一帧到 B,A 帧数不会发生变化,B 则会增加一帧。

删除指定帧

$ gifsicle source.gif --delete '#1-5' > output.gif

帧索引从 0 开始。

帧数支持负数,比如 #-1 表示倒数第一帧,#0--2 表示前 N - 2 帧。

修改帧与帧之间的 Delay Time

$ gifsicle source.gif -d100 '#0-5' > output.gif

TODO: 目前修改似乎有问题,只导出了修改后的帧。

注意,单位是 1/100 秒,-d100 表示延迟时间为 1s。

在线工具 Ezgif GIF Maker

Adding a delay to the end of an animated gif

MP4 转 GIF

使用 FFmpeg

$ ffmpeg -vf "fps=10" -loop 0 target.gif -i source.mp4

图片旋转

使用 ImageMagick

convert source.png -rotate 90 target.png

想起再继续补充...

@toFrankie toFrankie added 2023 2023 年撰写 生活随笔 一些杂七杂八的文章 labels Nov 10, 2023
@toFrankie toFrankie changed the title GIF 图片操作记录 GIF 图片操作 Nov 10, 2023
@toFrankie toFrankie changed the title GIF 图片操作 图片操作记录 Nov 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2023 2023 年撰写 生活随笔 一些杂七杂八的文章
Projects
None yet
Development

No branches or pull requests

1 participant