Thanks to all those who sent me hints on how to do this. I ended up simply center cropping a 4:3 (or 3:4) section out of my APS scans because I found the fuzz/trim method left a bit too much of the white border behind. I also used some of Fred Weinhaus' hints to find the aspect ratio of the input image.
In case anyone is interested, I attach my working batch file. (Yes, I was obliged to do this on Windows. Sigh.) It can cope with 3328x1872 (16:9) APS scans and 1600x1200 (4:3) digital images in either landscape or portrait format - reducing them to 800x600 or 450x600 respectively. do_convert.bat -------------- @echo off if "%1"=="" goto usage if "%2"=="" goto usage set INFILE=%1 set OUTFILE=%2 set TEMPFILE=%INFILE% if not exist %1 goto noinfile convert %1 -format "%%w" info: > temp.txt set /p WIDTH= < temp.txt convert %1 -format "%%h" info: > temp.txt set /p HEIGHT= < temp.txt convert %1 -format "%%[fx:w/h]" info: > temp.txt set /p ASPECT= < temp.txt del temp.txt echo Processing %INFILE% into %OUTFILE% echo width is %WIDTH% echo height is %HEIGHT% echo aspect is %ASPECT% if "%ASPECT%"=="0.5625" goto too_tall if "%ASPECT%"=="1.77778" goto too_wide if "%ASPECT%"=="0.75" goto portrait if "%ASPECT%"=="1.33333" goto landscape echo ERROR Inputfile %1 has unknown aspect ratio %ASPECT%. Giving up. got end :too_tall echo Crop 3:4 middle ... set TEMPFILE=%OUTFILE%-TEMP convert %INFILE% -gravity center -crop 1692x2256+0+0 +repage %TEMPFILE% if not exist %TEMPFILE% goto noouttempfile goto portrait :too_wide echo Crop 4:3 middle ... set TEMPFILE=%OUTFILE%-TEMP convert %INFILE% -gravity center -crop 2256x1692+0+0 +repage %TEMPFILE% if not exist %TEMPFILE% goto noouttempfile goto landscape :portrait echo Resize portrait to 450x600 ... convert %TEMPFILE% -resize x450 +repage %OUTFILE% goto tidyup :landscape echo Resize landscape to 800x600 ... convert %TEMPFILE% -resize x600 +repage %OUTFILE% goto tidyup :tidyup if NOT "%TEMPFILE%"=="%INFILE%" del %TEMPFILE% goto end :noinfile echo ERROR Inputfile "%INFILE%" does not exist goto usage :noouttempfile echo ERROR Could not create temporary outputfile "%TEMPFILE%" goto usage :nooutfile echo ERROR Could not create outputfile "%OUTFILE%" goto usage :usage echo Usage: do_convert inputfile outputfile :end _______________________________________________ Magick-users mailing list [email protected] http://studio.imagemagick.org/mailman/listinfo/magick-users
