[英]Convert all .jpg images in directory to .pdf | Debugging ImageMagick
I have found multiple posts regarding this issue and everyone is recommending ImageMagick but for me, it doesn't seem to work as intended and I don't see too many docs on their site regarding.jpg->.pdf conversion.我发现了多个关于这个问题的帖子,每个人都推荐ImageMagick但对我来说,它似乎没有按预期工作,我在他们的网站上没有看到太多关于.jpg->.pdf 转换的文档。
Is there some alternative, preferably CLI tool?是否有其他选择,最好是 CLI 工具?
Or can I somehow debug why ImageMagick doesn't work for me?或者我可以以某种方式调试为什么 ImageMagick 对我不起作用? I don't get any errors I just get corrupted files as a result.
我没有收到任何错误,我只是收到损坏的文件。
My usecase我的用例
I have tried these commands:我试过这些命令:
magick 0.jpg 0.pdf
but in both cases, I am unable to open the out.pdf file because it is corrupted.但在这两种情况下,我都无法打开 out.pdf 文件,因为它已损坏。 I have noticed that I can only convert 0.jpg file to pdf correctly but when I try to convert any other of my 64 jpg files then as a result I am getting a corrupted.pdf file
我注意到我只能正确地将 0.jpg 文件转换为 pdf 但是当我尝试转换我的 64 个 jpg 文件中的任何其他文件时,结果我得到了一个损坏的.pdf 文件
For example:例如:
This gives me the correct.pdf:这给了我正确的.pdf:
magick 2.jpg 2.pdf
but this gives me corrupted.pdf:但这给了我损坏。pdf:
magick 2.jpg 2.pdf
I assume that this a reason why I can't merge all of the files into one not corrupted.pdf file and my assumption is that there is something wrong with the rest of my.jpg files but I have no idea how to debug this issue.我认为这是我无法将所有文件合并到一个未损坏的文件的原因。pdf 文件,我的假设是 my.jpg 文件的 rest 有问题,但我不知道如何调试此问题. Every other.jpg file looks exactly the same as the one.jpg I can convert and all of them open without issues.
每个 other.jpg 文件看起来都与我可以转换的 one.jpg 完全相同,并且它们都可以毫无问题地打开。
magick identify -verbose foobar.jpg results: magick identify -verbose foobar.jpg结果:
I can convert 0.jpg file to.pdf correctly but 2.jpg results in corrupted.pdf.我可以正确地将 0.jpg 文件转换为.pdf,但 2.jpg 会导致损坏.pdf。 There are some apparent differences but I am not sure what those properties mean in the context of.jpg ->.pdf conversion
有一些明显的差异,但我不确定这些属性在 .jpg ->.pdf 转换的上下文中是什么意思
One thought is that someone has converted the grayscale image to color with 3 equal channels so that it IM says it has colorspace RGB.一种想法是有人将灰度图像转换为具有 3 个相等通道的颜色,因此 IM 说它具有色彩空间 RGB。 However, the JPEG colorspace tag is 2, which says it has no specific colorspace.
但是,JPEG 颜色空间标记为 2,表示它没有特定的颜色空间。
Properties:
date:create: 2021-04-01T17:29:06+00:00
date:modify: 2021-04-01T05:18:58+00:00
exif:ExifOffset: 46
exif:ExifVersion: 48, 50, 50, 48
exif:PixelXDimension: 960
exif:PixelYDimension: 1508
exif:Software: Google
jpeg:colorspace: 2
jpeg:sampling-factor: 2x2,1x1,1x1
From the JPG docs来自 JPG 文档
ColorSpace色彩空间
0 = Bi-level
1 = YCbCr, ITU-R BT 709, video
2 = No color space specified
3 = YCbCr, ITU-R BT 601-1, RGB
4 = YCbCr, ITU-R BT 601-1, video
8 = Gray-scale
9 = PhotoYCC
10 = RGB
11 = CMY
12 = CMYK
13 = YCCK
14 = CIELab
It is possible that this conflict or lack of colorspace may confuse certain viewers after the file is imbedded in a PDF vector shell.在将文件嵌入到 PDF 矢量 shell 中后,这种冲突或缺少色彩空间可能会使某些查看者感到困惑。
Thank you @Mark Setchell for pointing me in the right direction by sharing this command:感谢@Mark Setchell 通过分享此命令为我指明了正确的方向:
magick identify -verbose XXX.jpg
My images are grayish so I don't know why majority of the files has sRGB
colorspace but after converting colorspace to Gray
I can convert them to.pdf properly (I don't see any difference when I open up my.jpgs after conversion to grayscale).我的图像是灰色的,所以我不知道为什么大多数文件都有
sRGB
颜色空间,但是在将颜色空间转换为Gray
后,我可以正确地将它们转换为 .pdf (当我在转换为灰度)。
Using this command I can change colorspace to Gray
:使用此命令,我可以将颜色空间更改为
Gray
:
magick 2.jpg -colorspace gray gray2.jpg
Then I can convert "grayscale".jpgs to.pdf by simply:然后我可以简单地将“灰度”.jpgs 转换为.pdf:
magick gray2.jpg gray2.pdf
PS If anyone has some better solution I will gladly accept it but if nothing shows up I am going to accept this PS如果有人有更好的解决方案,我会很乐意接受,但如果没有出现,我会接受
@fmw42 Here is a .zip file that contains @fmw42 这是一个.zip 文件,其中包含
>magick 20.jpg 20.pdf
>magick 20.jpg 20.pdf
>magick 20.jpg -colorspace gray gray20.jpg
>magick 20.jpg -colorspace gray gray20.jpg
将源图像转换为灰色>magick gray20.jpg gray20.pdf
>magick gray20.jpg gray20.pdf
将色彩空间更改为灰色Keep in mind that this image is from some weird manga but I have tried to pick the most normal page (it was harder than it seemed to be but this image itself is not nsfw)请记住,这张图片来自一些奇怪的漫画,但我试图选择最正常的页面(它比看起来更难,但这张图片本身不是 nsfw)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.