How does Google’s Page Speed lossless image compression work?

If you’re really interested in the technical details, check out the source code: png_optimizer.cc jpeg_optimizer.cc webp_optimizer.cc For PNG files, they use OptiPNG with some trial-and-error approach // we use these four combinations because different images seem to benefit from // different parameters and this combination of 4 seems to work best for a large // … Read more

How to CREATE a transparent gif (or png) with PIL (python-imaging)

The following script creates a transparent GIF with a red circle drawn in the middle: from PIL import Image, ImageDraw img = Image.new(‘RGBA’, (100, 100), (255, 0, 0, 0)) draw = ImageDraw.Draw(img) draw.ellipse((25, 25, 75, 75), fill=(255, 0, 0)) img.save(‘test.gif’, ‘GIF’, transparency=0) and for PNG format: img.save(‘test.png’, ‘PNG’)

Easiest way of saving wpf Image control to a file

You could use RenderTargetBitmap class and BitmapEncoder. Define these methods: void SaveToBmp(FrameworkElement visual, string fileName) { var encoder = new BmpBitmapEncoder(); SaveUsingEncoder(visual, fileName, encoder); } void SaveToPng(FrameworkElement visual, string fileName) { var encoder = new PngBitmapEncoder(); SaveUsingEncoder(visual, fileName, encoder); } // and so on for other encoders (if you want) void SaveUsingEncoder(FrameworkElement visual, string fileName, … Read more

How to calculate the average rgb color values of a bitmap

The fastest way is by using unsafe code: BitmapData srcData = bm.LockBits( new Rectangle(0, 0, bm.Width, bm.Height), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); int stride = srcData.Stride; IntPtr Scan0 = srcData.Scan0; long[] totals = new long[] {0,0,0}; int width = bm.Width; int height = bm.Height; unsafe { byte* p = (byte*) (void*) Scan0; for (int y = 0; y … Read more