There is such a code:
$imagejpeg = imagecreatefromjpeg("test.jpg");
$imagejpeg = imagecropauto($imagejpeg, IMG_CROP_WHITE);
header('Content-Type: image/jpeg');
echo imagejpeg($imagejpeg);
I attach a picture of test.jpg. And the result of the script. For some reason, only the right side of its background is cropped. I've tried to remove some borders with imagecrop (by 10px width and height) and apply the imagecropauto function - it didn't help. I tried after applying imagecropauto to rotate the picture with imagagerotate and then apply imagecropauto again - didn't work. Why does it not work? How do I crop the background of an image? Open pictures in a new tab (in chrome when viewing jpg black background), because on toster white background and picture has white background. You can't see what's cropped and what's not.
Before applying the script:

After applying the script: