Godaddy won’t enable mod_gzip for me, so I have to use headers like this:
<?php
ob_start ("ob_gzhandler");
header("Content-type: text/css; charset: UTF-8");
header("Cache-Control: must-revalidate");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
$offset = 60 * 60 * 24 * 7;
$ExpStr = "Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT";
gmdate("D, d M Y H:i:s",
time() + $offset) . " GMT";
header($ExpStr);
?>
In this case, that would be for CSS files
Anyways, how can I use that with my images? I mean, making the image: image.php and putting that code at the top but using header("Content-type: image/png; charset: UTF-8"); doesn’t work so, let me know.
In general, gzipping GIF,PNG or JPEG images will not yield gains over a couple percent (in fact, the “compressed” file may be larger than the original). If you really want to do that in plain php, use mod_rewrite(or modified image URLs) to redirect the URLs to a php script. Then, outputting the image like
does work (in your experiments, you have probably inadvertently added spaces into a binary PNG image and thereby broken it).