Page 1 of 1

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

Posted: 2016-01-05T07:57:23-07:00
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

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

Posted: 2016-01-05T08:53:24-07:00
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

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

Posted: 2016-01-05T09:06:01-07:00
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.

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

Posted: 2016-01-05T09:33:41-07:00
by glennrp
Netpbm (pnmtopng) can read the file. Recent IM6-Q16 and IM7-Q8 both reject it.

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

Posted: 2016-01-05T09:56:57-07:00
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?

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

Posted: 2016-01-05T10:34:51-07:00
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.

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

Posted: 2016-01-05T10:45:31-07:00
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!

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

Posted: 2016-01-05T11:02:12-07:00
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.

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

Posted: 2016-01-05T11:37:59-07:00
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.