exec("convert input.png -evaluate multiply 16 -depth 8 -gaussian-blur 20 -white-threshold 40 output.png");
IM does not need to change from 1-bit to 8-bit, explicitly, as far as I know. It will handle it. That is unless you have a value of 0,1 in a range of 0-65535. Then you need to auto-stretch the values. If it is already full black and full white, then IM will treat is as 0 and 65535 (i.e. keep it full black and full white).
I don't understand the use of -evaluate multiply 16, unless your 16-bit data has a range that is 1/16 of full dynamic range. If not, then it will cause your data to overflow full white. If you want to auto stretch the data to full dynamic range, you can use -auto-level (if on a relatively current version of IM). -gaussian-blur 20 should probably be replaced with radiusxsigma or 0xsigma. typically sigma will be about radius/3 if left out or radius=3sigma if radius=0 for any given sigma. see
http://www.imagemagick.org/script/comma ... ssian-blur. However, you can speed it up dramatically by using -blur. See
http://www.imagemagick.org/script/comma ... s.php#blur. -white-threshold 40 is going to threshold at 40 out of 65535. You would be better using a meaningful percent threshold -white-threshold 40%. Note -white-threshold will not make your image binary. For that you need to use -threshold. IM will use values in your quantum range for compile Q16 (0-65535) even though you tell the output to be -depth 8. To remove 5-pixels all around use -shave 5x5.
Try
exec("convert input.png -auto-level -blur 20 -auto-level -white-threshold 40% -shave 5x5 -depth 8 output.png 2>&1",$out,$returnval);
print_r($out[0]);
or
exec("convert input.png -auto-level -blur 0x6.7 -auto-level -white-threshold 40% -shave 5x5 -depth 8 output.png 2>&1",$out,$returnval);
print_r($out[0]);
and see what messages are returned.
What version of IM are you using?
Try
<?php
exec("/usr/local/bin/convert -version",$out,$returnval);
print_r($out[0]);
?>
or
<?php
exec("/usr/bin/convert -version",$out,$returnval);
print_r($out[0]);
?>
or to find the path to convert, try
<?php
exec("type -a convert",$out,$returnval);
print_r($out[0]);
?>