Problems with Fred's downsize script

A plethora of command-line scripts that perform geometric transforms, blurs, sharpens, edging, noise removal, and color manipulations.
Posts: 11
Joined: 2012-06-16T01:13:18-07:00
Authentication code: 13

Problems with Fred's downsize script

Post by Nemo_bis »

I'm trying to use ... /index.php to reduce some JPEG-2000 images to a specified target size, per viewtopic.php?p=127981#p127981 Thank you for providing this useful utility!

It would be useful to know some examples of formats and environments that the script has been tested with. I'm testing on fedora 23 but the end user needs it on OSX.

1) bash complains about -gt expecting a unary operator at line 239 because at the line

Code: Select all

fullsize=`convert $tmpA1 ${ftype}:- | convert - -ping -format "%b" info: | tr -d "[:alpha:]"`
the fullsize variable fails to be defined. I don't understand the -ping mechanics, is this expected to work with JP2? If I knew where the file is created I could work around with something like

Code: Select all

if [ -z $fullsize ]; then
  fullsize=$(du "$outfile" | cut -f1 )
2) The same size comparison fails in some cases, for instance when the size ends up being expressed in floating point. Example with an echo for the two compared variables:

Code: Select all

$ ./ -s 2500 -t 15 Scan0001.jp2 0001.jp2                                                                                    
./ line 244: [: 2.5e+06: integer expression expected
3) suggests to use ksh but then there are compatibility issues:

Code: Select all[91]: whence: not found
dirname: operando mancante
Try 'dirname --help' for more information.
basename: operando mancante
Try 'basename --help' for more information.
4) The same attempt with ksh gave also

Code: Select all

convert: unable to write pixel cache `/tmp/magick-21362ZcAQ8qAzXoHy': Spazio esaurito sul device @ error/cache.c/WritePixelCachePixels/5525.
convert: unable to extend cache `./downsize_1_21321.mpc': Spazio esaurito sul device @ error/cache.c/OpenPixelCache/3728.
I'm not sure if it simply failed to defined the options correctly or if it's an issue with the file. It's a 24 bit JPEG image of 10 MPx.

User avatar
Posts: 26383
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problems with Fred's downsize script

Post by fmw42 »

I have never tried my script with JP2. Did you install openjpeg v2.1.0_0 delegate library? What do you get from

Code: Select all

convert -version
It could be your large image and amount of scaling, since you are getting scientific notation. Perhaps some part of the code does not work with scientific notation.

I have made some guesses as what might be the cause and found also that IM may have changed the way %b is reported. So I tried to fix that also. Try downloading the script and test it again.

If it fails, can you provide your input file so I can test with it? Upload it to some free hosting service such as and put the URL here.