GoogleCloudPlatform / appengine-java-standard

Google App Engine Standard Java runtime: Prod runtime, local devappserver, Cloud SDK Java components, GAE APIs, and GAE API emulators.
Apache License 2.0
197 stars 45 forks source link

ImageService.composite - Overlaying a transparent PNG no longer works as expected #239

Closed codeconsole closed 1 month ago

codeconsole commented 4 months ago

I have used the following for the past 10 years for watermarking an image. Its behavior stopped working correctly on 5/10/24 and has been broken ever since. Previously it would lay a transparent PNG on top of a photo, but now the non-transparent parts of the PNG are 100% white. What changed 5/10/24 that broke everything?

Image originalImage = ImagesServiceFactory.makeImageFromFilename(...)

List<Composite> listComposites = new ArrayList<>();
listComposites.add(ImagesServiceFactory.makeComposite(originalImage, 0, 0, 1, Composite.Anchor.TOP_LEFT));

Image wmk = imagesService.applyTransform(ImagesServiceFactory.makeResize(width, height),
    ImagesServiceFactory.makeImage(toByteArray(new ClassPathResource("watermark/watermark.png").getInputStream())),
    ImagesService.OutputEncoding.PNG);
listComposites.add(ImagesServiceFactory.makeComposite(wmk, 0, 0, 1, Composite.Anchor.CENTER_CENTER));

return imagesService.composite(listComposites, width, height, 0xFFFFFFFFL, ImagesService.OutputEncoding.JPEG);
ludoch commented 4 months ago

I doubt it is a client side bug, I need to investigate with the backend team, or an automatic JDK change? Just to be sure: which java runtime are you using? Did you try another one?

codeconsole commented 4 months ago

The app was java8. It started occurring continuously on 5/10/24 after running successfully for years. Same result after migrating to java21. Most likely a backend issue because I don't see anything in the ImageService java code that would cause it.

ludoch commented 4 months ago

Can you share the AppId/Projectd and service/version names? SREs would like to see some backend logs

codeconsole commented 4 months ago

It was a nasty issue and I didn't have time to wait for it to get fixed. I since removed my dependency on ImagesServiceFactory and now do all of the watermarking using java directly. I can probably create a sample app to replicate the issue when I get some time, but it wasn't random and happened every time so it should be easy for you guys to replicate.

ludoch commented 1 month ago

The image server backend pushed a fix that should be in prod now. Can you try again. Sorry for this regression