Answer the question
In order to leave comments, you need to log in
Automatic photo crop on the site?
There is a photo of the product on a white background. The proportions of the photo are always the same, but the product itself can occupy a different area - some are practically inscribed in the entire size, some products are small and not always correctly centered.
What about the order of actions I see:
1. Calculate the boundaries of the object without a background and cut off the background.
2. Add 40-50px white padding to all edges.
3. Knowing the width and height of the resulting object and the proportions of the final photo, we determine on which side we enter the object in these proportions, fill the background with white so that the output is a photo of the same format. The width/height will be different, but that doesn't matter. Proportions are important.
The result should be something like:
These photos are needed to import to the site. You need to either prepare them in advance before downloading, or teach Bitrix to do it yourself. Tell me, please, in which direction to dig, or how to correctly set the task for the programmer, if he has not done this before?
Answer the question
In order to leave comments, you need to log in
Photoshop + action in 4 buttons. Merge the entire folder locally and set an action on it in batch mode. By means of server software IMHO this is unrealistic.
We used this service for this on a project, but I don’t remember exactly how I set it up, maybe you can find something
https://docs.imgproxy.net/object_detection?id=usag...
In fact, automating this business is not difficult at all.
4 cycles start up and that's it.
The first cycle runs from top to bottom, horizontally, until the color of the pixel is white (if there are different shades of white, just compare its brightness: (r + g + b) / 3).
As we found a dark pixel, then we determined the upper border.
And the same for the other 3 sides.
Then crop along these coordinates.
UPD:
PS: the green arrow accidentally came out)
when cropping, subtract N pixels from the found coordinates so that the photo is not glued to the edges.
There are many ways to optimize here.
for example, in order not to go over every pixel, you can every 10 or 50 pixels, as you find a dark pixel, move backwards to find the beginning.
UPD2: there, in the answers above, they offer photoshops, etc. If zhto one-time work, then it is possible and so.
if the content manager is constantly loading images, etc. then it needs to be automated.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question