ImageMagick 因密度值不正确的 JPEG 而崩溃
ImageMagick crashing for JPEG with incorrect density value
我正在尝试使用 ImageMagick 转换图像。我正在裁剪并重采样到 112 DPI:
convert myimg.jpg -crop 1024x683+0+0 -resize 100% -resample 112 downsample.jpg
一个脚本遍历许多不同 DPI 的图像并对它们进行缩减采样。
但是,某个特定文件破坏了脚本。不知何故,该文件的 DPI 为 1(?!?)所以它最终尝试从 1 采样到 112,并且尝试耗尽我所有的 RAM 并挂起脚本。
identify -verbose myimage.jpg
Image: myimage.jpg
Format: JPEG (Joint Photographic Experts Group JFIF format)
Class: DirectClass
Geometry: 1024x683+0+0
Resolution: 1x1
Print size: 1024x683
是否有 argument/flag 我可以与 ImageMagick 一起使用来防止这种情况发生,也许是告诉它只进行下采样的东西?
您的错误是否与...有关
For formats which do not support an image resolution, the original resolution of the image must be specified via -density on the command line prior to specifying the resample resolution.
我知道 JPEG 支持分辨率,但可能它在 EXIF header 中是错误的,或者在某种程度上与嵌入的缩略图不明确/混淆(同样,可能假定单位)。我会更仔细地研究 [-density
] 参数 (http://www.imagemagick.org/script/command-line-options.php#density) 以及它与某些格式的分辨率和密度的关系。
至于让你的脚本工作。似乎您可能想将操作分解为更多单独的操作?如果您不能通过使用 -density
来满足 convert
我会考虑测试您知道失败的情况,然后跳过。可以解析 identify
的结果或只是 convert
的失败。您正在 shell 调用中执行这些 PHP 是吗?
我正在尝试使用 ImageMagick 转换图像。我正在裁剪并重采样到 112 DPI:
convert myimg.jpg -crop 1024x683+0+0 -resize 100% -resample 112 downsample.jpg
一个脚本遍历许多不同 DPI 的图像并对它们进行缩减采样。
但是,某个特定文件破坏了脚本。不知何故,该文件的 DPI 为 1(?!?)所以它最终尝试从 1 采样到 112,并且尝试耗尽我所有的 RAM 并挂起脚本。
identify -verbose myimage.jpg
Image: myimage.jpg
Format: JPEG (Joint Photographic Experts Group JFIF format)
Class: DirectClass
Geometry: 1024x683+0+0
Resolution: 1x1
Print size: 1024x683
是否有 argument/flag 我可以与 ImageMagick 一起使用来防止这种情况发生,也许是告诉它只进行下采样的东西?
您的错误是否与...有关
For formats which do not support an image resolution, the original resolution of the image must be specified via -density on the command line prior to specifying the resample resolution.
我知道 JPEG 支持分辨率,但可能它在 EXIF header 中是错误的,或者在某种程度上与嵌入的缩略图不明确/混淆(同样,可能假定单位)。我会更仔细地研究 [-density
] 参数 (http://www.imagemagick.org/script/command-line-options.php#density) 以及它与某些格式的分辨率和密度的关系。
至于让你的脚本工作。似乎您可能想将操作分解为更多单独的操作?如果您不能通过使用 -density
来满足 convert
我会考虑测试您知道失败的情况,然后跳过。可以解析 identify
的结果或只是 convert
的失败。您正在 shell 调用中执行这些 PHP 是吗?