You need to write a program to remove the background

In general, there is a jpg picture with a white background, it needs to be converted to transparent. The language is not particularly important, but PHP or C is better so that the application is cross-platform. The question is, which libraries/languages ​​are best to use? I tried opencv, but I think it takes a long time to deal with it, and there is not much time.
Do not offer this option, too much noise

<?php
    if(is_uploaded_file($_FILES["filename"]["tmp_name"])) {
        echo("success");
        move_uploaded_file($_FILES["filename"]["tmp_name"], "/var/www/html/image-creator/".$_FILES["filename"]["name"]);
        $im = ImageCreateFromPng($_FILES["filename"]["name"]);
        $col = imagecolorat($im,0,0);
        imagecolortransparent ($im, $col);
        imagecopyresampled ($im, $im, 0, 0, 0, 0, imagesx($im), imagesy($im), imagesx($im), imagesy($im));
        imagepng($im,"transparent-".$_FILES["filename"]["name"]);
        $preview = imagecreatetruecolor(88,87); 
        imagecopyresampled ($preview, $im, 0, 0, 0, 0, 88, 87, imagesx($im), imagesy($im));
        $col = imagecolorat($preview,0,0);
        imagecolorset($preview, $col, 255, 255, 255);
        imagepng($preview,"preview-".$_FILES["filename"]["name"]);
        imagedestroy($preview);   
        imagedestroy($im); 
    } else {
        echo("  ");
    }
?>

Answer 1, authority 100%

Sorry in advance if I didn’t understand exactly what your task is and what the problem is.

1) JPG itself does not support transparency. Therefore, you need PNG for example (at least as an output format) – and most importantly, enter PNG instead of JPG in the search engine. 😉

2) If you need cross-platform, then I would recommend Java, since support for images of different formats is there directly in the API. There are many code snippets on the Internet (for example, a similar question on stackoverflow) – if it does not help, write – I will find it in my own bins.

3) One of the JPG problems for you will be that the white background is not completely white (that’s why you see “a lot of noise”, as I understand it), you need to define some “threshold” background level and check each point – if it is lighter, then mask it with transparency.

UPD: Found (mine)

protected void makeImagesTransparent(BufferedImage[] imgs) {
    for(int i = 0; i < imgs.length; i++) {
        BufferedImage bi = new BufferedImage(imgs[i].getWidth(), imgs[i].getHeight(),
                BufferedImage.TYPE_INT_ARGB);
        bi.getGraphics().drawImage(imgs[i], 0, 0, null);
        DataBuffer ar = bi.getAlphaRaster().getDataBuffer();
        int transpColor = ar.getElem(0);
        for (int j = 0; j < ar.getSize(); j++) {
            int color = ar.getElem(j);
            //       ""
            if (((color >> 16) & 0xFF) + ((color >> 8) & 0xFF) + (color & 0xFF) > 700)
                ar.setElem(j, color & 0x00FFFFFF);
        } // for
        imgs[i] = bi;
    } // for
} // makeImageTransparent

4) And yes, the white color in the center will also be replaced with a transparent one, if this is not desirable, then you must not just go through all the points, but use the fill algorithm. True, this does not fit into the example very well.