Resize image with transparent background maintaining transparency

Today I faced a problem when I was resizing image in one of my project. Actually he problem was that I was using image resize code from one of my old project which were working fine earlier but not today. It is making my image background dark black which I obviously don’t need.

Reason for that code not working today is that earlier I always used jpg images for resizing and for that my old code was fine. Today when I tested same code with transparent background png file it gave me that awkward result. Keep on reading