To remove the white color of an image you can use a php script like the one below.
<?php
$img = imagecreatefromjpeg("imagemexemplo.jpg");
$white = imagecolorallocate($img, 255, 255, 255);
imagecolortransparent($img, $white);
imagepng($img,'imagemexemploalterada.png');
It is important to note that this script will only remove white and not near white colors. If the image quality is not the best you will have to remove pigments close to white. For this you can make other iterations of the same functions by taking the output image using imagrecreatefrompng(...)
and passing other values instead of $white = imagecolorallocate($img, 255, 255, 255);
.
The accuracy of your algorithm will depend a lot on the quality and lighting where photos are taken.
Finally, you’ll need an algorithm to remove transparent areas of your image to make it easier to center on css.
A problem with this solution is the case where a white garment appears transparently inside the garment if it removes many colors close to white (this is the worst case you should test).
Another important point about these image manipulations in php is the memory allocation limit that can be reached if the photos are large (but can be easily changed in php.ini)
Yes. PHP? JS? which language would you like to do this?
– MarceloBoni
I haven’t thought about the language yet, but PHP would be ideal, because I have more facility. However, if JS is simpler, it can also be. @Marcelobonifazio
– Indaiara Ribeiro
Just one more thing, how do you define the background of an image? In this case, a white background?
– MarceloBoni
For example, I’m going to have a background image one, dummy, and I want to put an outfit on top, but the image can’t have a white background, it has to be transparent. @Marcelobonifazio
– Indaiara Ribeiro
So deep down you just want to superimpose one image on the other
– MarceloBoni
Yes, I need all images of clothes that I upload to the system to be in the same style as the dress in the image, because the intention is for the user to take a picture of an outfit, and put it on the dummy. @Marcelobonifazio
– Indaiara Ribeiro
Let’s go continue this discussion in chat.
– Indaiara Ribeiro