You can reduce the size of the image by compressing it using some lostless or lossy algorithm of compression. JPEG is lossy, for example. If your image is already compressed using lossy compression, you can improve compression factor at the expense of lower image quality. At moderate degrees of lower quality you might not notice any defects, but further "improvements" of compression will make an image really ugly.
Important! Never edit compressed image! By doing it, you can degrade image even without increase in the compression factor, just because of several save operations accumulating defects. Keep uncompressed image, or, better, an image using lostless compression and always start conversion to JPEG or lossy PNG from this non-compromised sample.
[EDIT] Code is irrelevant here. You can have an image compression code, but this can be quite a big work.
—SA