JPEG 的无损裁剪(剪切和粘贴)

发布于 2024-12-12 19:35:28 字数 417 浏览 0 评论 0原文

我正在寻找无损 jpeg 操作的示例/博客文章/等(裁剪 n drop = 剪切和粘贴)。我知道有一个程序jpegtran(http://jpegclub.org/jpegtran)可以执行无损裁剪(在某些情况下),但似乎缺乏良好的文档。是的,我已经尝试过谷歌。

jpegtran 还有一个实验分支,允许在某些情况下无损删除(=粘贴),但其文档似乎更糟糕。

jpegtran 的 drop 开关是实验性的吗?它有已知问题吗?人们使用它吗?

drop 似乎是一个非常酷且有用的功能,我觉得奇怪的是它已经实验了 10 多年......

是的,人们可以使用无损格式(例如 PNG)来进行此类操作,但我我对 JPEG 特别感兴趣。

谢谢!

I'm looking for examples/blog posts/etc of lossless jpeg operations (crop n drop = cut and paste). I know there is a program jpegtran (http://jpegclub.org/jpegtran) which can perform lossless cropping (in certain situations), but there seems to be a lack of good documentation. Yes, I have tried the google.

jpegtran also has an experimental branch that allows lossless dropping (= pasting) in certain situations, but the documentation of this seems to be even worse.

What about jpegtran's drop switch is experimental? Does it have known issues? Do people use it?

drop seems like a really cool and useful feature, and I find it odd that it's been experimental for over 10 years...

And yes, one could use lossless formats such as PNG for such operations, but I'm specifically interested in JPEGs.

Thanks!

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

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

发布评论

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

评论(2

ら栖息 2024-12-19 19:35:29

我花了太多时间试图解决这个问题,所以希望这对其他人有帮助。当搜索关于这个所谓的“crop 'n drop”功能的文档时,这个问题在谷歌上的排名相当高。

概述:

jpegtran -drop 允许您将块从一个 JPEG“拖放到”另一个 JPEG 上。

它仅替换现有块,不会扩展输入,因此您无法仅使用 -drop 连接两个 JPEG。

但是,如果您提供的 -crop 参数大于输入图像,JPEGTran 将写出空白(灰色)块以扩展到所需的大小。然后您可以使用 -drop 将这些新的空白块替换为您想要的图像。

看我蹩脚的 ASCII 艺术示例:

  1. 您有两个图像,A.jpgB.jpg,尺寸均为 256x256 。我们希望将这些并排连接以生成 512x256 图像。

    <前><代码>+---------+ +---------+
    | | | |
    | A.jpg | | B.jpg |
    | | | |
    +---------+ +---------+

  2. “取消裁剪”A.jpg 至所需的大小。 -crop 参数是标准 X11 几何表示法:WIDTHxHEIGHT+X+Y 正 X/Y 值分别从顶部/左侧开始测量,负值从底部/右侧开始测量。

    jpegtran -crop 512x256+0+0 -outfile O.jpg A.jpg
    
    +---------+---------+
    | \ |
    | O.jpg \(空白)|
    | \ |
    +---------+---------+
    
  3. 现在将 B.jpg 拖放到 O.jpg 中新的空白部分 -drop 参数仅使用原点 X /Y 坐标。

    jpegtran -drop +256+0 B.jpg -outfile O.jpg O.jpg
    
    +---------+---------+ +---------+
    | \ | | |
    | O.jpg \ o<========| B.jpg |
    | \ | | |
    +---------+---------+ +---------+
    
  4. 完成!您现在有一个文件 O.jpg,尺寸为 512x256,其中包含 A.jpg的串联内容B.jpg

    <前><代码>+--------------------+
    | |
    | O.jpg |
    | |
    +--------------------+

注意:

  • A.jpgB.jpg 必须具有相同的高度。如果 B.jpg 较高,则会被剪掉。如果 A.jpg 较高,则图像的右侧将有一个空白的填充条。
  • A.jpg 的宽度必须以完整块结束。 (通常意味着可以被 8 整除?)
  • B.jpg 可以具有任意宽度,并且不必是块大小的倍数。

I spent entirely too much time trying to figure this out, so here's hoping this helps someone else. This question is pretty high on Google when searching for docs on this so-called "crop 'n drop" feature.

Overview:

jpegtran -drop allows you to "drop" the blocks from one JPEG onto another JPEG.

It only replaces existing blocks, it will not expand the input, so you cannot concatenate two JPEGs with only -drop.

However, if you supply a -crop parameter larger than the input image, JPEGTran will write out blank (grey) blocks to expand to the desired size. You can then use -drop to replace these new, blank blocks with your desired image.

Behold my crappy ASCII-art example:

  1. You have two images, A.jpg and B.jpg, both have dimensions of 256x256. We want to concatenate these side-by-side to produce a 512x256 image.

    +---------+  +---------+
    |         |  |         |
    |  A.jpg  |  |  B.jpg  |
    |         |  |         |
    +---------+  +---------+
    
  2. "Uncrop" A.jpg to the size required. The -crop parameter is standard X11 geometry notation: WIDTHxHEIGHT+X+Y Positive X/Y values measure from the top/left, and negative values from the bottom/right, respectively.

    jpegtran -crop 512x256+0+0 -outfile O.jpg A.jpg
    
    +---------+---------+
    |         \         |
    |  O.jpg  \ (blank) |
    |         \         |
    +---------+---------+
    
  3. Now "drop" B.jpg into the new, blank section in O.jpg The -drop parameter uses just the origin X/Y coordinates.

    jpegtran -drop +256+0 B.jpg -outfile O.jpg O.jpg
    
    +---------+---------+    +---------+
    |         \         |    |         |
    |  O.jpg  \    o<========|  B.jpg  |
    |         \         |    |         |
    +---------+---------+    +---------+
    
  4. Done! You now have a single file, O.jpg, with dimensions of 512x256, that contains the concatenated contents of A.jpg and B.jpg

    +-------------------+
    |                   |
    |       O.jpg       |
    |                   |
    +-------------------+
    

Notes:

  • A.jpg and B.jpg must have equal height. If B.jpg is taller, it will be cut off. If A.jpg is taller, the right side of the image will have a blank strip of padding.
  • A.jpg must have a width that ends on a complete block. (Usually means divisible by 8?)
  • B.jpg may have any width, and does not have to be a multiple of the block size.
薄荷梦 2024-12-19 19:35:29

jpegtran 手册页和两个 Windows 应用程序(JpegCropJpegJoin)相当不错。如果您有想要完成的特定过程,请更新您的问题以进行解释。

我自己在公司主页上使用 -drop 对 JPEG 进行无损分割:
http://bestelec.co.uk/images/front/features.jpg

  1. 首先,我将原始照片裁剪下来(在像素边界上)以包含所需的框架。此步骤可以使用非 JPEG 格式无损保存。 [艺术指导]
  2. 接下来,我根据网页设计的要求将这些图像缩小到必要的宽度。再次,无损保存,因为这些是中间步骤。
  3. 然后我通过 cjpeg 使用各种质量选项运行它们,直到找到我满意的最低质量设置。
  4. (可选)接下来,我裁剪了每个降低质量的单个图像的底部边缘,以与垂直轴上的倒数第二个 MCU 边界对齐。这使我能够将照片无间隙地排列在垂直条中。我的网页设计不需要一定的高度,所以我可以在这里自由选择一个。如果您的组件图像的范围未与 MCU 边界对齐(正如我的右边缘未对齐),请确保您使用的是 2012 年 10 月版本的 jpegtran/JpegJoin,否​​则只有第一张图像会显示为未裁剪的。
  5. 最后,我将这些图像合并成一个 jpeg,并通过 jpegtran -optimise -progressive -copy none 运行结果,使其尽可能小且渐进。

最终结果是我将 3 个 HTTP 请求减少为 1 个,从而允许更早地请求同一主机上的后续资源并缩短加载时间。对我来说,这比将图像转换为 WebP 并单独提供它们来说是一个更大的胜利,特别是考虑到我们的大多数企业访问者都使用 IE。

The jpegtran man page and the two windows apps (JpegCrop and JpegJoin) are fairly good. If you have a specific procedure you are trying to accomplish, please update your question to explain it.

Myself, I have used -drop to do lossless spriting of JPEGs on my company home page:
http://bestelec.co.uk/images/front/features.jpg

  1. First, I cropped the original photos down (on pixel boundaries) to encompass the frame required. This step can be saved losslessly using a non-JPEG format. [Art direction]
  2. I next scaled these images down to the necessary width as required by the web design. Again, saved losslessly since these are intermediate steps.
  3. Then I ran them through cjpeg with various quality options, until I found the lowest quality setting I was comfortable with.
  4. (Optional) Next I cropped the bottom edge of each reduced quality individual image to align with the penultimate MCU boundary on the vertical axis. This allowed me to join the photos in a vertical strip with no gaps. My web design doesn't require a certain height so I was free to choose one here. If your component images' extents are not aligned on MCU boundaries (as my right edges were not), be sure you are using the October 2012 build of jpegtran/JpegJoin, otherwise only the first image will show up uncropped.
  5. Lastly, I joined the images together into one jpeg, and ran the result through jpegtran -optimise -progressive -copy none to make it as small as possible, and progressive.

The net result is I have reduced three HTTP requests to one, allowing subsequent resources on the same host to be requested earlier and improving load times. This was a bigger win for me than converting the images to WebP and serving them individually, especially given that most of our corporate visitors are using IE.

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