So every now and then I need to use an image on the web that has a gradient in the alpha channel. Naturally that limits your choice to a 24 bit png. There is another option that I'm be curious to explore, and that is to automate, via a php script, to merge the png with the underlying colour or image, and save it as a jpg. But that's one of those projects I'll never get to.
so speaking of the PNGs... I did some tests to try to minimize the size. I've created an image with a diagonal gradient of a murky green to a murky yellow, and an alpha layer that was a soft circle.
(A) The original file was 13.46k

Then I went about different techniques to try and get the size down to half, without a noticeable difference.
(B)first I removed everything in the RGB layer that was black in the Alpha Layer. that resulted in a 12.06 k image. (10.4% less)
photoshop will save RGBA data for each pixel, and if we make all pixels that have A=0 have R,G and B equal to 0, there will less data write, since there is so much repetition
(C)Next I posterized the RGB layer (after adding minimal noise to hide the steps) and removed the invisible areas(same as B). The resulting image was 11.78k, hardly an improvement (additional 2% difference). The reason is that I used a posterization setting of 96. The gradient together with the use of colours that don't like to get posterized make it a hard image to do this to.
(D) Same as C, but I tried a posterization setting of of 64. Result: 9.32k. Alhough 30% less than the original (and 20% less than C), the image quality has visibly degraded.
(E) Next up - positerize the alpha layer. Again I had to use a high value(96) to get a good result. The reason is that the first step is too harsh, so you get a strong outline if you use a low value. Again, I deleted the nonvisible area(trick B) and I got 11.09k (18% less that original, 6% lass than C). The nice thing about this is that the colours were not posterized, thus giving a nicer image.
I should note that in order to posterize the alpha layer I had to apply a curve. As stated before, the steps from posterizing gave a harsh outline. I applied a curve to the alpha layer that was diagonal around at the highlights and shadows, and drew about 16-20 steps throughout the rest, then applied the prosterization at 96. This is a good time (if not sooner) to realize that posterization is not the right way to do this. Posterization creates regular steps in each layer (RGB). This is why certain colours are so hard to match using posterization. All along I'm just trying to acheive the same results as indexing the colours. Photoshop however won't let you index 24bit PNGs. And indexing them in 8bit PNG will result in a matted alpha layer (that's why we need to use 24bit PNGs).
Bottom line is that the solution is in indexing the colours.
This may not work for images that have a merged alpha layer straight out of Photoshop. (though there is a way to retrieve this information, as each pixel has RGBA info). So if you can get the colour layer with the alpha layer not merged, these are the steps I took:
- copy the colour layer to a new document.
- switch the colour mode (under image>mode) to indexed.
- then select the indexing to your liking
- copy the result into a new image (or back into the original)
- copy the alpha layer (alt-click on alpha layer and copy)
- paste into new document (make sure the document is RGB, it will default to grescale)
- switch the colour mode to indexed and select the desired number of colours, this can be less that what "looks good" or close to original, since it is not as noticeable in the alpha layer
- copy into the alpha layer of the indexed colour layer.
My result (after trimming the dead area) 6.8k - 50% of the original image, and the images were almost indistinguishable at 100%. Upon closer inspection, the steps in the gradient were visible, but at 50% less on a grad-fill, it's pretty good.
Original | Compressed

Your mileage may vary depending on the type of image and number of colours indexed, but I think this is a typically "bad scenario" of an image.