Page 1 of 1

Problems with Fred's downsize script

Posted: 2016-02-02T04:08:41-07:00
by Nemo_bis
I'm trying to use http://www.fmwconcepts.com/imagemagick/ ... /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 )
fi
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

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

Code: Select all

downsize.sh[91]: whence: downsize.sh: 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.

Re: Problems with Fred's downsize script

Posted: 2016-02-02T16:53:45-07:00
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 dropbox.com and put the URL here.