Transparent background image

3

I wonder if it is possible to upload an image and leave a certain part of the image (the background) transparent. I would like to overlay this image.

The mannequin is the fixed background image, and the dress is the image that I want to upload with the transparent background.

    
asked by anonymous 29.09.2015 / 04:01

1 answer

1

To remove the white color from an image you 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 remove only white and not colors that are close to white. If the image quality is not the best you will have to remove pigments close to white. For this you can do other iterations of the same functions by taking the output image using imagrecreatefrompng(...) and passing other values in place of $white = imagecolorallocate($img, 255, 255, 255); .

The accuracy of your algorithm will depend greatly on the quality and lighting where the photos are taken.

Finally you will need an algorithm to remove the transparent areas of your image to make it easier to centralize in css.

A problem in this solution is if a white suit appears transparently inside the suit if you remove many colors close to white (this is the worst case you should try).

Another important point about these manipulations in php images is the memory allocation limit that can be reached if the photos are large (but can be easily changed in php.ini)

    
16.10.2015 / 09:31