![]() ![]() You will only need to provide the input image, and output image path and the quality range that you want for your PNG file and that's it, now you're using pngquant with PHP. Execute the build command (compress the image) Set the rangeo of the quality of the image Use this method to overwrite if it exists pngquant throws an error if the output file exists >setOutputImage("/a-folder/image-compressed.png") Path (and filename) of the output compress image To compress a PNG image you will need to use at least 3 methods in a instance of PNGQuant: setImage("/a-folder/image-original.png") The PNGQuant class will do the trick for you. In the same way that the command line does, the PNGQuant class adds a method for every argument and option available in the CLI of pngquant, which makes the usage with php very intuitive. Or in case that you don't use Composer, just download the PNGQuant.php class of the repository and add it into your code using require_once. If you use composer, you can install it executing the following command in your console: composer require ourcodeworld/php-pngquant php-pngquant is a simple wrapper for the awesome pngquant CLI. You can use the php-pngquant library to work with pngquant. If the installation method for your operative system isn't available here, please refer to the homepage of pngquant. As mentioned previously, you can use pngquant with PHP using a wrapper library that will make the usage pretty easy or you can execute with plain PHP a console command to achieve your goal. You can install pngquant using brew: brew install pngquant ![]() To install pngquant in ubuntu, you can install it from a custom repository executing the following command in a terminal: sudo add-apt-repository ppa:danmbox/ppa You can download an executable of pngquant for windows from this link. pngquant is available for almost all the operative systems and can be downloaded directly from the official website here. You will need the command line version of pngquant installed on your machine and it needs (not a must, but recommendable) accesible from the path. In this article, you will learn how to use pngquant with PHP using either a library or with plain PHP. The best of all, it can be used with PHP. Generated images are compatible with all modern web browsers, and have better fallback in IE6 than 24-bit PNGs. The conversion reduces file sizes significantly (in most of the case up to 70% of the filesize and almost with the same quality) and preserves full alpha transparency. Pngquant is a command-line utility and a library for lossy compression of PNG images. To compress PNG files, you can use the known png compression library pngquant. Unlike JPGs, which create artifacts and blur images at a certain point, a PNG file will always look at least as sharp as the original image.įor you as a developer, the format is not of importance (unless you explicitly need a special format), what matters here, is the way in which you handle the images and if you compress them, specially if you want to take care about the loading time of your website, the space they occupy in the hard disk of your server etc. PNG files are a lossless format, meaning that compression doesn't affect the quality of the image. Designers need the ability to incorporate low-resolution images that load quickly but also look great, too (not as well as SVG that can be scaled, but acceptable). PNG files were developed to build upon the purpose of gifs. Each one has its place for use on websites (either as part of the UI or just user uploads). GIF, JPG and PNG files are the three main image formats used for the web, the difference between them is the resulting image.
0 Comments
Leave a Reply. |