在 LaTeX 中自动将图片调整为 A4 大小

发布于 2024-07-30 06:55:03 字数 488 浏览 7 评论 0原文

我有很多图片,每张图片的尺寸差异很大。

我的目标是开发一种算法,允许您删除多余的空格。 此类算法用于信号处理中,以消除冗余噪声,例如在移动电话中。

该算法应按如下方式使用

 \includegraphics[crop-redundant-whitespace]{picture.png} 

函数 crop-redundant-whitespace 应更改 include 命令,例如,

 \includegraphics[width=2.5cm, height=5.0cm]{picture.png}

该算法应

  • 检测长度至少为 2cm 且彼此分离的部分
  • ,如果存在许多大部件,那么应该选择最大的部件。

如何自动调整图片大小并使其固定为 A4?

I have many pictures which size differ much from picture to picture.

I aim to develop an algorithm which allows you to remove the extra whitespace. Such algorithms are used in Signal Processing in removing the redundant noise, for instance in mobile phones.

The algorithm should be used as follows

 \includegraphics[crop-redundant-whitespace]{picture.png} 

The function crop-redundant-whitespace should change the include -command, for instance to

 \includegraphics[width=2.5cm, height=5.0cm]{picture.png}

The algorithm should

  • detect parts of size at least 2cm in length which are separate from each other
  • if many large parts exist, then the biggest part should be selected.

How can you automatically resize pictures and make them fix to A4?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

仙女 2024-08-06 06:55:03

这并不是一个真正的 LaTeX 问题;而是一个 LaTeX 问题。 可以对文档中包含的图像执行任意转换,但检测图像中的空白与 LaTeX 的有用功能范围相去甚远。

弄清楚如何使用 ImageMagick 或其他工具来完成此操作,然后询问如何与 LaTeX 进行交互。

This isn't really a LaTeX question; it is possible to execute arbitrary conversions on images you include in the document but detecting whitespace in an image, say, is very very far away from LaTeX's useful range of abilities.

Work out how to do it with ImageMagick or whatever, and then ask how to interface that with LaTeX.

Saygoodbye 2024-08-06 06:55:03

您可以使用 epstopdf 的 shell 转义功能对图像执行任意转换。 以下是对包含的每个 PDF 文件执行 pdfcrop 的示例:

\documentclass{article}
\usepackage{graphicx,epstopdf}
\DeclareGraphicsRule{.pdf}{pdf}{-crop.pdf}{`pdfcrop #1}
\begin{document}
\fbox{\includegraphics[scale=0.5]{essai}}% => change this to a real PDF
\end{document}

然而,我在 TeX Live 2009 的预发行版本中遇到了问题; 现在不能花任何时间进行调试,但可以看看在旧系统上的运行情况。

即使这对您来说效果很好,但效率相当低,因为它必须在每次编译文档时运行。 我建议只预处理你的图像。

You can perform arbitrary conversions on images with the shell-escape feature of epstopdf. Here's an example of pdfcrop being executed on each PDF file that is included:

\documentclass{article}
\usepackage{graphicx,epstopdf}
\DeclareGraphicsRule{.pdf}{pdf}{-crop.pdf}{`pdfcrop #1}
\begin{document}
\fbox{\includegraphics[scale=0.5]{essai}}% => change this to a real PDF
\end{document}

However, I'm having trouble getting this in a pre-release version of TeX Live 2009; can't spend any time debugging now but see how you go on any older system.

Even if this works fine for you, this is pretty inefficient since it has to run every time the document is compiled. I'd suggest just preprocessing your images.

放赐 2024-08-06 06:55:03

粗糙且准备就绪:

\documentclass[a4paper]{article}

\begin{document}
\resizebox{\textwidth}{\textheight}{\includegraphics*{compatible_image_file}}
\end{document}

但您会失去纵横比。 将其中一个长度替换为“!”以保留比例。 您还可以在整个图形周围粘贴 \rotatebox 来修复纵向/横向不兼容问题。

使用 \includegraphics 的方括号样式参数,看起来像:

\includegraphics[width=\textwidth, height=\textheight]{compatible_image_file}

这可能比我已经拖了 15 年的嘎吱作响的古老戏法更最新。 必须更新我的个人 bog-o-tricks 文件...

如果您发现默认的空白空间太大,则可以使用通常的边距欺骗。 您可能会考虑使用 slides 类。 我认为默认边距更接近页面边缘。

Rough and ready:

\documentclass[a4paper]{article}

\begin{document}
\resizebox{\textwidth}{\textheight}{\includegraphics*{compatible_image_file}}
\end{document}

but you'll lose the aspect ratio. Replace one or the other length with "!" to preserve the ratio. You could also stick a \rotatebox around the whole graphics include to fix a portrait/landscape incompatibility.

Using the square-bracket style arguments to \includegraphics, would look like:

\includegraphics[width=\textwidth, height=\textheight]{compatible_image_file}

which is probably more up-to-date than the creaking ancient cantrip that I've been lugging around for 15 years. Must update my personal bog-o-tricks file...

The usual margin diddling is applicable if you find the default whitespace to be too expansive. And you might consider using the slides class. I think the default margins are closer to the edge of the page.

与风相奔跑 2024-08-06 06:55:03

不要重新发明轮子,从此处重新混合。

\newcommand{\adjustimg}{% Horizontal adjustment of image
  \ifodd\value{page}\hspace*{\dimexpr\evensidemargin-\oddsidemargin}\else\hspace*{-\dimexpr\evensidemargin-\oddsidemargin}\fi%
}
\newcommand{\centerimg}[2][width=\textwidth]{% Center an image
  \makebox[\textwidth]{\adjustimg\includegraphics[#1]{#2}}%
}

\begin{document}
\mbox{} \par
\noindent\centerimg[width=\paperwidth,height=\paperheight]{tiger}

现在有一个问题:页面上有一些奇怪的白色上面板,不知道为什么,但我认为这比其他答案更接近(至少对我来说并没有真正起作用)——请参阅参考资料。

信息

  1. 有点类似的问题此处

Do not reinvent the wheel, remixed from here.

\newcommand{\adjustimg}{% Horizontal adjustment of image
  \ifodd\value{page}\hspace*{\dimexpr\evensidemargin-\oddsidemargin}\else\hspace*{-\dimexpr\evensidemargin-\oddsidemargin}\fi%
}
\newcommand{\centerimg}[2][width=\textwidth]{% Center an image
  \makebox[\textwidth]{\adjustimg\includegraphics[#1]{#2}}%
}

\begin{document}
\mbox{} \par
\noindent\centerimg[width=\paperwidth,height=\paperheight]{tiger}

Now one problem: it has some odd white upper panel of white on the page, no idea why but I think this is closer than other answers (not really working at least for me) -- please see the reference.

Info

  1. a bit similar question here
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文