JPEG的无损裁剪(剪切和粘贴) [英] Lossless crop n drop (cut and paste) for JPEGs
问题描述
我正在寻找无损jpeg操作的示例/博客文章/等(裁剪n drop =剪切和粘贴)。我知道有一个程序 jpegtran
(http://jpegclub.org/jpegtran)可以执行无损裁剪(在某些情况下),但似乎缺乏好文档。是的,我试过谷歌。
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
还有一个实验分支,允许无损丢弃(=粘贴)在某些情况下,但这个文件似乎更糟糕。
jpegtran
also has an experimental branch that allows lossless dropping (= pasting) in certain situations, but the documentation of this seems to be even worse.
jpegtran的 drop
切换是实验性的?它有已知问题吗?人们会使用它吗?
What about jpegtran's drop
switch is experimental? Does it have known issues? Do people use it?
drop
似乎是一个非常酷且实用的功能,我觉得很奇怪它是已经实验超过10年...
drop
seems like a really cool and useful feature, and I find it odd that it's been experimental for over 10 years...
是的,可以使用PNG之类的无损格式进行此类操作,但我对JPEG特别感兴趣。
And yes, one could use lossless formats such as PNG for such operations, but I'm specifically interested in JPEGs.
谢谢!
推荐答案
我花了太多时间试图解决这个问题出来,所以这里希望这有助于其他人。在这个所谓的裁剪功能上搜索文档时,Google上的这个问题相当高。
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.
概述:
jpegtran -drop
允许您将块从一个JPEG拖放到另一个JPEG上。
jpegtran -drop
allows you to "drop" the blocks from one JPEG onto another JPEG.
它只替换现有的块,它不会扩展输入,所以你不能只用 -drop
连接两个JPEG。
It only replaces existing blocks, it will not expand the input, so you cannot concatenate two JPEGs with only -drop
.
但是,如果提供大于输入图像的 -crop
参数,JPEGTran将写出空白(灰色)块以扩展到所需大小。您可以然后使用 -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.
看看我糟糕的ASCII艺术示例:
Behold my crappy ASCII-art example:
-
你有两张图片,
A.jpg
和B.jpg
,两者的尺寸均为256x256
。我们希望将这些并排连接以生成512x256
图像。
You have two images,
A.jpg
andB.jpg
, both have dimensions of256x256
. We want to concatenate these side-by-side to produce a512x256
image.
+---------+ +---------+
| | | |
| A.jpg | | B.jpg |
| | | |
+---------+ +---------+
Uncrop A.jpg
达到所需尺寸。 -crop
参数是标准X11几何表示法:WIDTHxHEIGHT + X + Y正X / Y值分别从上/下测量,负值从下/右测量。
"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) |
| \ |
+---------+---------+
现在放弃 B.jpg
进入 O.jpg
中新的空白部分 -drop
参数仅使用原点X / Y坐标。
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 |
| \ | | |
+---------+---------+ +---------+
完成!您现在有一个文件 O.jpg
,尺寸为 512x256
,其中包含<$的连接内容c $ c> A.jpg 和 B.jpg
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 |
| |
+-------------------+
注意:
-
A.jpg
和B.jpg
必须具有相同的高度。如果B.jpg
更高,它将被切断。如果A.jpg
更高,图像的右侧将有一个空白的填充条。 -
A.jpg
的宽度必须以完整的块结尾。 (通常意味着可被8整除?) -
B.jpg
可以有任何宽度,并且不必是块大小。
A.jpg
andB.jpg
must have equal height. IfB.jpg
is taller, it will be cut off. IfA.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.
这篇关于JPEG的无损裁剪(剪切和粘贴)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!