OpenCV is not made to deal with alpha channels. it can read and write the format. it has no functions to operate on such pictures. there is no easy fix, no single function to do what you need. this issue needs some thought.
the issue with alpha channels is that most people don’t know how they really work, how to work with them.
let’s take the black lines adjacent to transparent areas. pixels in the fully transparent region don’t matter, so they can have arbitrary RGB values, but pixels on the edge do matter. those have to have the same color value as fully opaque pixels, and the alpha channel modulates that.
if such a picture is resized trivially, adjacent fully transparent pixels, which have arbitrary RGB values, get mixed into the edge pixels’ color, and that destroys things. the resize completely ignores the alpha channel in its operation, treats all channels separately.
what you need to do is fill those transparent (alpha 0) pixels’ values from neighboring non-0 pixels.
there are likely a lot of ways to solve this, some may even be easy and cheap.
without giving it much thought, I’d advise to use inpainting. use (alpha == 0)
for the mask of pixels that need inpainting. you only need bordering pixels and they only need to replicate nearby non-transparent color. inpainting usually does way more than that.
perhaps use a mask like (alpha == 0) & dilate(alpha > 0)
, which only selects those adjacent pixels.
https://docs.opencv.org/master/df/d3d/tutorial_py_inpainting.html