I am using code very similar to (does the same thing as) the answer to this question: Crop whitespace from image in PHP. I have tried this exact code as well, to the same effect:
I find that it does not work (does not trim white space) with a PNG source, even if the background of the PNG is true white (not transparent). I can send the output to imagepng without issue, but if the image source is imagecreatefrompng, nothing is trimmed.
Is there a reliable way to trim whitespace from a PNG using GD? Or perhaps a way to convert the color white to transparent and trim that instead? Or, other solution…?
This is a totally untested guess. However, I would assume that alpha transparency is causing the issue. The answer that you mentioned might need a bit of work.
Perhaps try using
imagecopymerge()to lay the image over a white canvas, and then go through the steps mentioned in the answer.