+1 vote
by
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:
5f8622a1bd117110140694.jpeg


After applying the script:
5f8622ba149ee315705638.jpeg
by
Trust the automation, if the coordinates of the parts are about the same, you can cut a piece through imagecopyresampled

1 Answer

+1 vote
by
$imagejpeg = imagecreatefromjpeg(__DIR__ . '/test.jpg');
$imagejpeg = imagecropauto($imagejpeg, IMG_CROP_THRESHOLD, 1, 16777215);

header('Content-Type: image/jpeg');
echo imagejpeg($imagejpeg);
Result: 5f863deee976e724185829.jpeg
by
eugene159 , IMG_CROP_WHITE will work correctly if the background of the picture is purely white (
Are you sure that's the background of this picture? I'm not.

Are you sure that's the background of this picture? I'm not.
by
Why doesn't my code work? Why should I use IMG_CROP_THRESHOLD?
by
eugene159 Vitaly Artemyev
by
Vitaly Artemyev Vitaly Artemyev
...