[RESOLVED] Cannot convert one specific pgm file, others work fine

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
mimetus
Posts: 5
Joined: 2016-01-05T07:39:05-07:00
Authentication code: 1151

[RESOLVED] Cannot convert one specific pgm file, others work fine

Post by mimetus »

I have a bunch of pgm files that have all been processed in the same way, and I'm running a convert script on every file, and at least one file fails to convert.

Even if I run the following:

Code: Select all

convert F0023240.pgm test.pgm
It returns the following:

Code: Select all

convert.im6: negative or zero image size `F0023240.pgm' @ error/pnm.c/ReadPNMImage/416.
convert.im6: no images defined `test.pgm' @ error/convert.c/ConvertImageCommand/3044.
The file in question can be found here:https://www.dropbox.com/s/hkfzwb3i42721 ... 0.pgm?dl=0

I have no idea why this file does not work, i can view the file just fine in gimp and ubuntu image viewer.

I use the following version:

Code: Select all

convert -version
Version: ImageMagick 6.7.7-10 2014-03-06 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP 
Thanks
- Mimetus
Last edited by mimetus on 2016-01-05T12:40:36-07:00, edited 1 time in total.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Cannot convert one specific pgm file, others work fine

Post by glennrp »

  • glenn.rp> od -c F00* | head
    0000000 P 5 \n 8 3 2 7 6 8 \n 2 5 5 \n \n
    0000020 375 376 377 377 376 376 376 375 375 376 377 377 375 376 376 377
(a bit confusing, on screen I see a space between 832 and 768)
File length seems OK, 832 * 768 + 16 = 638992
  • glenn.rp> wc F*
    4 5 638992 F0023240.pgm
Last edited by glennrp on 2016-01-05T09:10:19-07:00, edited 2 times in total.
mimetus
Posts: 5
Joined: 2016-01-05T07:39:05-07:00
Authentication code: 1151

Re: Cannot convert one specific pgm file, others work fine

Post by mimetus »

Thanks for the reply.

This file have the exact same byte count and works fine with convert https://www.dropbox.com/s/ytx91s777zahd ... 5.pgm?dl=0

Code: Select all

~$ wc -c F0023240.pgm
638992 F0023240.pgm

~$ wc -c F0000015.pgm
638992 F0000015.pgm

~$ convert F0000015.pgm test.pgm

~$ convert F0023240.pgm test.pgm
convert.im6: negative or zero image size `F0023240.pgm' @ error/pnm.c/ReadPNMImage/416.
convert.im6: no images defined `test.pgm' @ error/convert.c/ConvertImageCommand/3044.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Cannot convert one specific pgm file, others work fine

Post by glennrp »

Netpbm (pnmtopng) can read the file. Recent IM6-Q16 and IM7-Q8 both reject it.
mimetus
Posts: 5
Joined: 2016-01-05T07:39:05-07:00
Authentication code: 1151

Re: Cannot convert one specific pgm file, others work fine

Post by mimetus »

So you suggest convert to png? That could be a workaround of course.
Thanks for your help! Though i guess the bug is still open?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Cannot convert one specific pgm file, others work fine

Post by magick »

Try
  • convert 'F0023240.pgm[0]' test.pgm
This file is corrupt. It ends with a 'P' after the image data so ImageMagick thinks there is another image in the file but fails when it can't find any.
mimetus
Posts: 5
Joined: 2016-01-05T07:39:05-07:00
Authentication code: 1151

Re: Cannot convert one specific pgm file, others work fine

Post by mimetus »

This works! Thanks a lot! Though I don't agree that the file is corrupt, it's structured according to the PGM specification, and other programs read the file just fine.

Thanks for the help!
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Re: Cannot convert one specific pgm file, others work fine

Post by magick »

Your PGM has a blank line between the maximum gray value and the image data. The PGM specification says:
  • The maximum gray value (Maxval), again in ASCII decimal. Must be less than 65536, and more than zero.
    A single whitespace character (usually a newline).
Suggesting your PGM is corrupt, it has *two* whitespace characters.
mimetus
Posts: 5
Joined: 2016-01-05T07:39:05-07:00
Authentication code: 1151

Re: Cannot convert one specific pgm file, others work fine

Post by mimetus »

I tried removing the extra whitespace character and you are correct, resulted in convert working again. Thanks allot!

Additionally, I can see that the programs that handled the image before are off by one pixel along the edge, translating it to the next row.
Post Reply