Getting white background image instead of transparent image on Cloudinary-AI background removal

Comments

6 comments

  • Avatar
    Stephen Doyle

    Hi Jennifer,

    What URL are you using to request the image after the background removal completed? If you request that we return a JPG image, JPEG doesn't support transparency so the background will be white (unless you specify a different color) 

    If you request a WEBP or PNG image, the background should be transparent, as those image formats support transparency

    Thanks,

    Stephen

    0
    Comment actions Permalink
  • Avatar
    Jennifer Heinz

    Hi Stephen,

    We have set up a notification endpoint. After background removal action is completed, we will receive the image url as part of the notification response like below. We will use the same url for downloading the image. At this point, we would like to get a transparent background image instead of a white background.

    Sample Response

    {
    "info_kind": "cloudinary_ai",
    "info_status": "complete",
    "public_id": "image",
    "uploaded_at": "2019-10-10T11:13:27Z",
    "version": 1562311741,
    "url": "http://res.cloudinary.com/services-gmbh/image/upload/v1562311741/image.jpg",
    "secure_url": "https://res.cloudinary.com/services-gmbh/image/upload/v1562311741/image.jpg",
    "etag": "a4488c28503513c4db2c03a7540d8f32",
    "notification_type": "info",
    "info_data": {
    "cloudinary_ai_hints": [],
    "cloudinary_ai_fine_edges": false
    }
    }

     

    Note: We will send all image formats to cloudinary background removal process

    0
    Comment actions Permalink
  • Avatar
    Stephen Doyle

    Hi Jennifer,

    The most common way of using images after the upload is to use one of our SDKs to create the URL corresponding to a particular derived (transformed) version of the image, such as by using the cloudinary_url() method, so if you're doing that you can just change the extension on the URL you're creating to get an output in the format you require, which I assume will be PNG or WEBP if you're performing background removal. 

    That said, I was surprised to see you're getting a .jpg URL as the original URL in the HTTP notification *after* the background removal completes so I'm going to check that with the development team. When you access the image details in the API or Media Library after the background removal add-on completes, you should see a PNG URL and I expected that would be the case in the notification also.

    As a workaround if you're unable to change the extension on the URL or if you're not making use of our other transformations functionality, you can update your upload API call or upload preset to convert the image to PNG as part of the upload.

    In that case, the 'original' will be saved as PNG so the 'url' and 'secure_url' fields will be a .png link both before and after the background removal.

    Regards,
    Stephen

     

     

     

    0
    Comment actions Permalink
  • Avatar
    Aryan Goharzad

    This was working fine for me, but after uploading a particular image, suddenly the behaviour of the API changed and now it's returning JPG urls for every upload. I'm sure I didn't change anything in my code, as I was testing my app for hours. Things were working fine, but after a particular moment, it stopped returning PNGs, and returned JPG urls instead. Unexpected behaviour from the API. 

    1
    Comment actions Permalink
  • Avatar
    Leon

    I am having the same issue. In the documentation https://cloudinary.com/documentation/cloudinary_ai_background_removal_addon#asynchronous_handling it says that it will return a .png url. However it is returning me a .jpg in the post to my notification endpoint.

    0
    Comment actions Permalink
  • Avatar
    Loic Verger Del Bove

    Hi Leon,

    Do you mind sharing the URL you are getting? I'd like to check our logs.

    Thanks in advance.

    Best,

    Loic

    0
    Comment actions Permalink

Please sign in to leave a comment.