Search code examples
image-processingterminalimagemagickimagemagick-convert

ImageMagick no longer works with threshold parameters on png images after ImageTragick patch


I have code that has been successfully monochroming (making black and white) images, for both jpg and pngs for awhile now. Recently I noticed that it is not longer working for pngs. When I run this for a png, I get an empty image with the correct dimensions. For a jpg I get correct result.

convert -density 150 -threshold '50'% -fuzz 1% -transparent white 'input.png' 'output.png'

I discovered it's the threshold that isn't working, when removed the image is no longer blank, but of course is no longer monochrome as well.

convert -density 150 -fuzz 1% -transparent white 'input.png' 'output.png'

I have found that converting the png to a jpg before running still results in a blank image.

convert 'input.png' 'input.jpg'
convert -density 150 -threshold '50'% -fuzz 1% -transparent white 'input.jpg' 'output.png'

I've also tried restructuring the command as suggested in the comments, but still getting the same results.

convert 'input.png' -threshold '50'% -transparent white 'output.png'

I tested this on an instance that doesn't have the ImageTragick secuirty patch and it did not have this issue, so I am fairly confident that the issue arrived when I updated ImageMagick. I am currently using 7.0.2-0.

What is causing this behavior, and how can I use ImageMagick 7.0.2-0 Convert to monochrome a png image?

Update: as requested, here's one of the many png images I've used for testing.

enter image description here


Solution

  • Credit to MArk Setchell in the comments

    Not sure what is going on, but does this do what you want?

    convert buckeroos.png -threshold 50% -alpha off -transparent white output.png
    

    Perhaps it's the escapeshellarg and escapeshellcmd I run on the parameters and command which add those ' marks that are breaking it.