What image formats do you use? I see you are writing a PNG, that can be both a paletted image and a non-paletted image. What formats do you read?
I don't know why the output is PNG. As I said in the original question, this is old code that is being refactored. As the images are all real pictures of properties and the like, it would be much better if they were JPGs but that means changing lots of other code where they are read. I will be changing all the PNG files to JPG files, probably manually, and then updating the code that reads the files then revisiting this code that writes them to ensure in future everythings is JPG. But that's for another time.
The input file is a stream from a website upload. The format could be any image format although practically it is likely to be a JPG as most of them will have originated from a digital camera which mostly produce JPG files.
Call isTrueColor() on your GD objects, should return true
A call of $image->isTrueColor() immediately before writing to the file does indeed return true.