Please note that because most image formats are already compressed, you gain nothing from compressing them. Therefore you should not compress jpg, gif, png files. In fact, doing so may actually increase the amount of data that has to be transferred to the web visitors, which is the opposite of what you would want.
For PHP pages, add the following to .htaccess:
php_value zlib.output_compression On
Alternatively (preferred), add this into .user.ini