Skip to main content
Known Participant
April 22, 2024
Frage

Unexpected aliasing on shape layers when exporting with Save for Web

  • April 22, 2024
  • 5 Antworten
  • 3030 Ansichten

This issue has been giving me issues for quite a long time and I've finally tracked down the issue. When exporting images in Photoshop using the legacy Save for Web interface, which is particularly useful for pixel art, if there are shape layers, when scaling the image down, unintended aliasing appears around the edges of the shapes, particularly in areas where the rectangular bounds seem to overlap. This produces noticable, visual artifacts that should never be there.

This is happening on Photoshop 25.6.0 on Windows 11.

 

Here are the steps to reproduce:

  1. Create a new document, fairly large at about 2000x2000.
  2. Draw a red triangle on one side of the canvas.
  3. Create a circle somewhere else on the canvas, away from the triangle.
  4. Go to the Save for Web dialog.
  5. Scale the image down. Even as little as 1 pixel makes a difference but it's more noticable if it's scaled down more, like down to 200x200
  6. The original image on the left or top will have a slight red ring around the white circle.

 

A possible workaround is if the layers are exported separately instead of at the same time. Another possible workaround is if the red triangle layer is above the white circle, but this isn't always possible depending on the art. Rasterizing the layers does not work, but it does change how the aliasing turns out.

Attached is an example of how the image comes out if I set it to an indexed PNG-8 image with transparency and matting disabled. There's a clear red ring around the white circle that shouldn't be there.

Dieses Thema wurde für Antworten geschlossen.

5 Antworten

rayek.elfin
Legend
April 22, 2024

Ah, I see. Interesting. It seems that the legacy SFW will (for some reason) use red values to add anti-aliasing to the white circle when any other resampling method is used other than Nearest Neighbour.

 

But that only happens when the Quality setting isn't set to Nearest Neighbour, just as @D Fosse mentioned.

 

I tested this in other image editors and web image optimization tools, and only the legacy defunct Save for Web function in Photoshop behaves like this.

 

If I may ask: why are you scaling down shapes like this? I agree with @D Fosse that for pixel art you should be working at the native output resolution instead of downscaling shapes.

And why would you want to use the old SfW anyway? The new Export As function works better and doesn't introduce this buggy behaviour no matter the resampling method.

 

In any case: switch to Nearest Neighbour in SfW, and the problem goes away.

Known Participant
April 22, 2024

Well, not just red but the surrounding color. It could alias with a gradient color, which is what was happening in my project.

As I mentioned, this export method is essential when it comes to downscaling and color-reducing art from a higher resolution to a target size for pixel art. Sometimes that art will contain shapes or other layers which produce these unwanted artifacts.

Here is another project I worked on prior where the issue was more prevalent. I have this logo I'm trying to downscale and color reduce, but with a very specific transparent cutout in the center done as a hard edge, and anti-aliased on white on the outside. I've disabled transparency to enhance the defect. The part I have circled is how all of the inside should have appeared after downscaling, but due to this bug, nearly all of it is aliased. Particularly around the lower yellow circle where the edges almost seems to emit aliasing due to proximity.

 

Nearest neighbor scaling is not what I'm looking for in this case because I need the art to be smooth, even though the issue is not present in this state.

 

I eventually ended up manually cleaning up the aliasing from the first one after exporting because it was close enough to what I needed.

 

rayek.elfin
Legend
April 22, 2024

So... Why not use the new export function? That also supports scaling down.

 

All that said, I feel your pain, because Photoshop isn't exactly a forerunner in optimizing low resolution pixel art or downscaling larger version for prep to low resolution export, nor for colour reduction or file size optimization.

 

Myself, I avoid Photoshop entirely and rely either on Color Quantizer (for exact colour reduction control) or Squoosh. (Also use PhotoLine, which has good export options for pixel art.) Both allow for what you need to do. Squoosh also runs as an off-line app, but requires a local LAMP web server to run it in. CQ is a desktop app for Windows, but is predominantly PNG optimization oriented, while Squoosh supports the latest AVIF, OxiPNG, and other file formats.

 

https://squoosh.app/

http://x128.ho.ua/color-quantizer.html

 

Known Participant
April 22, 2024

It might depend on how the shape is drawn and possibly the scale size. I prepared a sample file similar to the example image in the first post. Trying to output this at about 200x200 should produce aliasing in Save for Web even on the original image.

https://www.dropbox.com/scl/fi/jiywmkoq7tpk6mxh0omry/save-for-web-aliasing-example.psd?rlkey=rfmmz5ee8ocrasc3wueamz9i3&dl=0

Known Participant
April 26, 2024

This aliasing issue may not be exclusive to Save for Web after all. In another graphic I worked on, I exported using the modern Export As and while the aliasing was not noticeable at first, when it gets processed or scaled by something else, the same aliasing present in Save for Web is noticeable. In this case, here is a closeup of the thumbnail produced by Discord. This is the same aliasing more easily noticed in Save for Web.

 

 

Where did this come from? It was certainly not in my source PSD or in the PNG file I exported.

Curiously, even the example image, if I were to save as a PNG, would exhibit aliasing upon export, even though it would just be a PNG image free of shape layers at that point. Something is going on with the core rendering or exporting in Photoshop because this is producing messy images all over.

rayek.elfin
Legend
April 26, 2024

That looks more like the anti-aliased edges' transparency is premultiplied with white.

The PNG spec states it shouldn't premultiply, but many applications ignore this rule.

 

Here is an example of premultiplying the transparent edge pixels with respectively black or white for comparison:

 

 

 

rayek.elfin
Legend
April 22, 2024

I tried to replicate this issue, but I can't. I experience no red anti-aliasing issues.

Known Participant
April 22, 2024

It depends on the use case. In my example, I have some art built at a higher resolution that I'm trying to scale down while retaining sharp edges and limited colors. Nearest Neighbor in that case may produce rather inaccurate shapes on the art due to the nature of the scaling algorithm. I'm not sure if this used to be the case before because I've had this workflow for several years now.

D Fosse
Community Expert
Community Expert
April 22, 2024

Use the Nearest Neighbor resampling algorithm. It's there for pixel art where you need to maintain crisp edges.

 

Pixel art should always be made at actual size so you don't have to resample at all.