asked on
PHP is a widely-used server-side scripting language especially suited for web development, powering tens of millions of sites from Facebook to personal WordPress blogs. PHP is often paired with the MySQL relational database, but includes support for most other mainstream databases. By utilizing different Server APIs, PHP can work on many different web servers as a server-side scripting language.
TRUSTED BY
2.With PNG, there is little to no room in terms of quality levels or anything like that. Usually you have 24-bit PNGs or 8-bit PNGs, where 24-bit PNGs have support for millions of colors while 8-bit PNGs have support for 256 colors. But if you open up an 8-bit PNG and re-save it as an 8-bit PNG, for example, there is no compression. If you open up a 24-bit PNG and save it as an 8-bit PNG, you'll get a lot smaller file size, but if the image had millions of colors, then you'll definitely notice quality loss because you're throwing out millions of colors and trying to force the picture into a much smaller palette of possible colors.
3. So if your source files are already JPEG and PNG, then there's probably not much you can do about them. Every once in a while, you might come across a 24-bit PNG that you could save as a high-quality JPEG and it would mostly look the same and have a smaller file size, but that's a rare case.
4. If your source files are things like BMPs (uncompressed bitmaps), then you can save a BMP to either JPEG or PNG and see a dramatic reduction in file size, because the source file isn't optimized in any way - it's just raw data.
5. If you want to RESIZE a very large image (e.g. you get a HUGE JPEG and you only need it at a smaller resolution), then that would reduce file size.
6. That said, your most simple option is just to use the command line utility ImageMagick, which can convert between different formats. And you can use PHP's shell_exec() (or similar) function to call it. If you can't use ImageMagick, then search for PHP scripts using the GD extension. Just remember, you can't very effectively optimize / compress an image that is already optimized / compressed.
If you're using a CMS like WordPress or something, there are a dozen different free plugins that will try to optimize your uploaded images for you.