简体   繁体   English

将目录下所有.jpg图片转换为.pdf | 调试 ImageMagick

[英]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我的用例


My os is Windows and I have 64.jpg files called 0.jpg, 2.jpg, ... 63.jpg and I would like to merge all those images into one.pdf file. 我的操作系统是 Windows,我有 64.jpg 文件,名为 0.jpg、2.jpg、... 63.jpg,我想将所有这些图像合并到一个.pdf 文件中。

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 文件,其中包含

  • 20.jpg - source image 20.jpg - 源图像
  • 20.pdf - corrupted pdf after running >magick 20.jpg 20.pdf 20.pdf - 运行后损坏的 pdf >magick 20.jpg 20.pdf
  • gray20.jpg - source image converted to gray by >magick 20.jpg -colorspace gray gray20.jpg gray20.jpg - >magick 20.jpg -colorspace gray gray20.jpg将源图像转换为灰色
  • gray20.pdf - source image converted to.pdf after changing colorspace to gray first by >magick gray20.jpg gray20.pdf gray20.pdf - 源图像转换为.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.

相关问题 在Imagemagick中转换多个图像(Windows) - Convert multiple images in Imagemagick (Windows) ImageMagick 的批处理命令在 Windows 上转换目录和子目录中的所有文件 - Batch command for ImageMagick to convert all files in a directory and sub-directories on windows 是否可以将目录中的所有文件重命名为0.jpg,1.jpg,2.jpg等? - Is it possible rename all files in a directory to 0.jpg, 1.jpg, 2.jpg, etc? 如何使用ImageMagick批量转换pdf并进行基准测试? - Howto batch-convert pdf's using ImageMagick and benchmark the process? PHP exec()在Windows上以文件名中的空格将pdf转换为jpg - PHP exec() convert pdf to jpg with space in filename on Windows 通过命令行:将(.tif和.pdf)转换为.jpg或.png - Via command line: convert (.tif and .pdf) to .jpg or .png 是否有任何脚本将文件夹图像转换为一个pdf - Is there any script to convert folder images into one pdf 如何在.bat文件(Windows)中使用ImageMagick调整所有子目录中所有图像的大小? - How would I use ImageMagick in a .bat file (Windows) to resize all images in all sub-directories? 如何列出子目录中的所有PNG图像? - How to list all PNG images in a sub directory? Windows Shell脚本转换目录中的所有文件 - Windows shell script convert all files in directory
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM