It should be clear that the set version of the function doesn't change the image it self, just the resource in memory, which probably is fine if you didn't save the image yet. If your use case is for an image that is already on disk, image you should always do something like:
imageresolution($img, 300, 300);
imagepng($img, $filname, $quality);