PS C:\Bugs\PDFTest> magick convert .\problematic.png prob.jp2
convert: Number of resolutions is too high in comparison to the size of tiles
`OpenJP2' @ error/jp2.c/JP2ErrorHandler/194.
convert: unable to encode image file `prob.jp2' @ error/jp2.c/WriteJP2Image/1089.
PS C:\Bugs\PDFTest> magick -version
Version: ImageMagick 7.0.8-11 Q8 x64 2018-08-29 http://www.imagemagick.org
Number of resolutions is too high
Number of resolutions is too high
Hello, I've stumbled into a bug (probably) either in ImageMagick or OpenJpeg2000 - while trying to convert small image like for example https://1drv.ms/u/s!AkG2rWqeWpmHhZI6tB-_C4anEJZAng I'm getting an error (tried with newest ImageMagick under W10). Some output:
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Number of resolutions is too high
First, if using IM 7, use magick, not magick convert and not convert. However, I get your same message for that input PNG using IM 7.0.8.11 Q16 and IM 6.9.10.11. But I can convert many other PNG files to JPG2 with no errors. So perhaps your PNG file is corrupt in some way. I have also tried several older version of ImageMagick and get the same issue.
P.S. You need OpenJPEG v2.1 or higher
P.S. You need OpenJPEG v2.1 or higher
Re: Number of resolutions is too high
@fmw42 Good to hear that you were able to reproduce the issue. The provided png is fine, not corrupted in any way I know, you can view it in any image browser, edit it or anything. The problem is probably related with image size somehow. The problematic image is just a cropped bitmap, if I choose less crop (bigger image) it gets converted fine to JP2, however with bigger crop (smaller image) you get the error.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Number of resolutions is too high
The problem isn't specific to that particular file. For example:
Tested with v7.0.7-28 on Windows 8.1.
Code: Select all
f:\web\im>%IMG7%magick -size 99x8 xc: x.jp2
magick: Number of resolutions is too high in comparison to the size of tiles
`OpenJP2' @ error/jp2.c/JP2ErrorHandler/193.
magick: unable to encode image file `x.jp2' @ error/jp2.c/WriteJP2Image/1072.
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Number of resolutions is too high
I confirm snibgo's command error using IM 7.0.8.11 Q16 Mac OSX Sierra
magick: Number of resolutions is too high in comparison to the size of tiles
`OpenJP2' @ error/jp2.c/JP2ErrorHandler/194.
magick: unable to encode image file `x.jp2' @ error/jp2.c/WriteJP2Image/1089
But this works fine:
as does
Code: Select all
magick -size 99x8 xc: x.jp2
`OpenJP2' @ error/jp2.c/JP2ErrorHandler/194.
magick: unable to encode image file `x.jp2' @ error/jp2.c/WriteJP2Image/1089
But this works fine:
Code: Select all
magick logo: logo.jp2
Code: Select all
magick lena.png lena.jp2
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Number of resolutions is too high
The problem seems to be high aspect ratios. For example, 99x16 and 16x99 are okay, but 99x15 and 15x99 fail.
snibgo's IM pages: im.snibgo.com
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Number of resolutions is too high
That does seem to be the case, at least this fails
magick: Number of resolutions is too high in comparison to the size of tiles
`OpenJP2' @ error/jp2.c/JP2ErrorHandler/194.
magick: unable to encode image file `tmp.jp2' @ error/jp2.c/WriteJP2Image/1089.
Code: Select all
magick logo:[640x20+0+0] tmp.jp2
`OpenJP2' @ error/jp2.c/JP2ErrorHandler/194.
magick: unable to encode image file `tmp.jp2' @ error/jp2.c/WriteJP2Image/1089.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Number of resolutions is too high
The issue is that jp2 has size limitations
This works:
But this fails:
But specifying one resolution works again
See https://www.imagemagick.org/script/jp2.php
So if your height is less than 32, you need to specify only one resolution.code blocks are 64 samples in width and 32 samples in height
This works:
Code: Select all
convert logo:[640x32+0+0] tmp.jp2
Code: Select all
convert logo:[640x20+0+0] tmp.jp2
Code: Select all
convert logo:[640x20+0+0] -define jp2:number-resolutions=1 tmp.jpg2
See https://www.imagemagick.org/script/jp2.php
Re: Number of resolutions is too high
JP2 hasn't got any size limitation. It's just the problem of setting the number of resolutions (or the default value). If you take a look at openjpeg2000 code at: https://github.com/uclouvain/openjpeg/b ... 2k.c#L7847 you will see that it compares the size of the tiles to 2^(n-1) if size in x or y is lower then exception is thrown. It means that any image can fail if appropriate number of resolutions is set -> for n = 32 you would probably have to have image with height/width bigger than 2^31.
Unfortunately I haven't got much time to find out how number of resolutions is calculated or what is the default value. The same is for size of a tile, however it seems that for small images it's just a with/height of the image.
Setting number of resolutions to 1 is not a solution, as it result in much bigger file due to lower compression. The fact that IM can work for some images and for others not - dependent only on image size, makes it little useless in case of conversion to that particular format.
Unfortunately I haven't got much time to find out how number of resolutions is calculated or what is the default value. The same is for size of a tile, however it seems that for small images it's just a with/height of the image.
Setting number of resolutions to 1 is not a solution, as it result in much bigger file due to lower compression. The fact that IM can work for some images and for others not - dependent only on image size, makes it little useless in case of conversion to that particular format.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Number of resolutions is too high
I will have to defer to the ImageMagick developers to comment further.