我正在尝试将我的 gif 文件添加到我的项目中。但是,互联网和论坛上的任何建议对我都不起作用。我只有 11 张图片,我将它们制作成 gif 文件。我如何才能像 gif 一样一次制作一个 gif 文件或多张图片?
答案1
编辑 您通常尝试过下面显示的许多方法,但收效甚微。若想在 Overleaf 上将文件转换为 PDF 动画,请尝试
1) 下载http://mirrors.ctan.org/macros/latex/contrib/animate/animate.pdf
2)将其放入工作文件夹(例如上传到 Overleaf)并添加此 MWE Reader.tex 文件
\documentclass[]{standalone}
\usepackage{graphicx,animate} % for \animategraphics
\begin{document} %http://mirrors.ctan.org/macros/latex/contrib/animate/animate.pdf
\noindent\animategraphics[scale=0.9,controls,step]{0}{animate}{}{}
\end{document}
您应该会得到一个 ONE Page reader.pdf。现在在合适的 PDF 动画阅读器(Acrobat、evince okular 等)中打开该文件。请注意,SumatraPDF 可以处理顺序页面,但不能处理动画页面。30 页的文档现在已动画化为 1 页,以供您快速阅读。尝试使用此示例的有限步骤控件来导航和阅读几个选定的段落。对于预先转换为顺序 PDF 的 GIF,您可以删除该“步骤”选项,并将 0 替换为更高的值。
GIF 转 PDF 很容易,但动画 GIF 转 PDF 需要 GIF 转 PDF^2,而动画非常适合这个^2部分
尝试过较旧或更常见的解决方案后,最有效的似乎是使用“动画”(嵌入图像或矢量)或更简单地在同一文件夹中调用外部 gif。
有很多方法可以将 GIF 帧转换为 PNG 或 PDF 以包含在 TeX 中,那么它们不需要作为附加文件提供。
如果 GIF 由全帧组成,则可以在 Windows 上将文件作为帧打开以进行演示或查看。SumatraPDF 的一个鲜为人知的功能是,多页 TIFF 或 GIF 帧可以像其他受支持的图像格式一样保存为 PDF。
对于一些可能的命令行转换,请参见帖子末尾。
\documentclass[11pt]{article}
%\documentclass[]{beamer}
%\usepackage{movie15} % for \includemovie AVOID as obsolete use media 9
\usepackage{media9} % for \includemedia AVOID as about to expire
% \usepackage{pdfpc-commands} % for \inlineMovie OK BUT needs own .sty file see below
% \usepackage{xmpmulti} % For \multiinclude OK BUT uses slides in a sequence
\usepackage{multimedia}
\usepackage{graphicx} % for \animategraphics
\usepackage{animate} % for \animategraphics
\usepackage{hyperref} % (for \includemovie AVOID) Is needed for href fallback but not in Beamer class
%\def\bold#1{\bf#1\normalfont}
\begin{document}
\Large \textbf{2019 comparison of GIF to TeX solutions}\normalsize
\par \vspace{0.5cm}
% OLD movie15 will sometimes work HOWEVER you need a PDF reader that allows extract and run contents
% You may need to create a visible marker and it needs to be able to open the system default gif viewer
% Note the GIF is embedded and some viewers may allow extraction but not run or may not see a media player
\noindent \textbf{Movie15} (Requires active Flash Player)\newline
Simpler to just run externally detached via fallback\newline
%Click here to run GIF externally \texttt{>} \includemovie{1cm}{1cm}{anim.gif}
\par \vspace{0.5cm}
% Newer Media9 can include gif converted to modern mp4 movie, For this to work the viewer needs to have a
% flash player installed this is depreciating and may not be useful technology soon
\noindent \textbf{Media9} (Requires active Flash Player)\newline
Simpler to just run externally detached via fallback\newline
\includemedia[activate=onclick,width=2cm,height=2cm,addresource=anim.mp4,flashvars={source=anim.mp4&autoPlay=true &loop=true}]{}{VPlayer.swf}
\par \vspace{0.5cm}
% Alternatively use well established AVI format with a special pdfpc style file NOTE requires that media
% permissions are relaxed to alow internal running
\noindent \textbf{pdfpc} (Requires Download from https://pdfpc.github.io/)\newline
% https://github.com/pdfpc/pdfpc#sample-presentations
Disabled here (see comments) but do consider for presentation use
\par
%\inlineMovie[loop&autostart&start=1]{test.avi}{/anims/frame-0.png}{height=0.7\textheight}}
\vspace{0.5cm}
% Simple to animate a sequence of PNGs, so for a subfolder /anims/ containing frame-0.png to frame-5.png
% for finer details on conversion from GIF to PNG etc see https://tex.stackexchange.com/questions/240243/
% For Beamer we can sequence a number of slides using multiinclude {xmpmulti}
\noindent \textbf{Multiinclude} (For Beamer)\newline
Disabled here (see comments) but do consider for presentation use
\par
%\begin{frame}
%\transduration<0-5>{3} % speed
%\multiinclude[<+->][format=png, graphics={width=4cm}]{anims/frame} % files MUST be named frame-0 and up
%\end{frame}
\vspace{1cm}
% Animate works well with internal embeded png
%\movie[height = 0.7 \textwidth,width = 1.0 \textwidth]{}{anim.gif} % also mp4 mpg etc
\noindent \textbf{Animate}\newline\par
\noindent First example is 6 x single PNGs \hfill Second example is GIF2PDF\\ \raggedleft{conversion via SumatraPDF}\\ \raggedright
\animategraphics[controls,loop,autoplay,scale=1]{6}{anims/frame-}{0}{5} %6 is the fps value to open PNGs
\hfill \animategraphics[controls,loop,autoplay,scale=1]{6}{anim}{}{} %6 is the fps value to Display pages
\par \vspace{1cm}
\noindent \textbf{System Failback}\newline Just simply run any file in its own platform default viewer\\
\href{run:./anim.gif} {Run my external animated gif}
\end{document}
如果使用命令行转换器来处理图像,一些有用的相关选项可能是
使用 gifsicle 将 GIF 转换为 PNG
gifsicle --unoptimize animated.gif | convert - frame-%d.png
使用 ImageMagick 将 PDF 转换为 GIF(不优化)
转换 -density 192 -delay 100 -loop 0 -background white -alpha remove input.pdf animated.gif
使用 ImageMagick 将 PDF 转换为 PNG(不需要,因为动画可以使用 PDF)转换 -density 192 -strip input.pdf PNG8:frames/frame-%02d.png
对于 PNG 到 GIF 的转换 -layers OptimizePlus -delay 100 -loop 0 frames/frame-?.png -delay 100 frames/frame-??.png animated.gif