To compress a PNG file to less than 100 KB in Linux, you can use tools like pngquant
or optipng
, which are designed to reduce the file size of PNG images without significant loss of quality. Here’s how you can use these tools:
Before we begin, we want to let you know you can use https://www.xconvert.com/compress-png to compress your PNG to 100KB online. You can choose Autoscale
feature to keep the quality high while reducing file size to less than 100KB.
1. Using pngquant
pngquant
is a popular lossy PNG compressor that reduces the number of colors in the image, resulting in a smaller file size.
Install pngquant
:
sudo apt-get install pngquant # For Debian/Ubuntu
sudo dnf install pngquant # For Fedora
sudo yum install pngquant # For CentOS/RHEL
Compress the PNG file:
pngquant --quality=65-80 --ext .png --force your-image.png
--quality=65-80
: Sets the quality range (from 65 to 80) for the compression. Lower values will reduce file size more but may also reduce quality.--ext .png
: Specifies the output file extension (overwrite the original file).--force
: Overwrites the original file if needed.
2. Using optipng
optipng
is another tool that performs lossless compression, which reduces file size without losing any image quality.
Install optipng
:
sudo apt-get install optipng # For Debian/Ubuntu
sudo dnf install optipng # For Fedora
sudo yum install optipng # For CentOS/RHEL
Compress the PNG file:
optipng -o7 your-image.png
-o7
: Sets the optimization level to 7 (maximum). Higher optimization levels take longer but usually yield smaller file sizes.
3. Using convert
from ImageMagick
If you already have ImageMagick installed, you can also use the convert
command to compress the image.
Install ImageMagick:
sudo apt-get install imagemagick # For Debian/Ubuntu
sudo dnf install imagemagick # For Fedora
sudo yum install imagemagick # For CentOS/RHEL
Compress the PNG file:
convert your-image.png -quality 80 -resize 800x800 compressed-image.png
-quality 80
: Adjusts the quality of the output image (you can reduce this number further to lower the file size).-resize 800x800
: Resizes the image to a maximum of 800×800 pixels (optional, if the image is very large).
4. Check the File Size
After compressing the file, you can check its size to ensure it is under 100 KB:
ls -lh compressed-image.png
Tips:
- If the file is still not under 100 KB, you may need to reduce the quality further or resize the image to a smaller dimension.
Featured photo by Matthew Moloney on Unsplash