To compress a JPG file to exactly or under 100 KB in Linux, you can use tools like jpegoptim
, convert
(from ImageMagick), or ffmpeg
. Here is a detailed guide on how to use these tools effectively:
Before we begin, we want to let you know you can use https://www.xconvert.com/compress-jpeg to compress your JPG/JPEG to 100KB online. You can choose Autoscale
feature to keep the quality high while reducing file size to less than 100KB.
1. Using jpegoptim
jpegoptim
is a tool designed to optimize and compress JPEG files, either with or without quality loss. You can specify a target size and let jpegoptim
handle the compression.
Install jpegoptim
:
sudo apt-get install jpegoptim # For Debian/Ubuntu
sudo dnf install jpegoptim # For Fedora
sudo yum install jpegoptim # For CentOS/RHEL
Compress the JPG File:
To reduce the file size while maintaining acceptable quality:
jpegoptim --size=100k your-image.jpg
--size=100k
: Sets the target size to 100 KB.jpegoptim
will adjust the compression level to meet this target.
2. Using convert
from ImageMagick
convert
from ImageMagick is versatile for image manipulation, including adjusting quality and resizing to achieve the desired file size.
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 JPG File:
Since ImageMagick doesn’t directly allow specifying a target size, you may need to adjust the quality iteratively:
convert your-image.jpg -quality 80 -resize 1024x768 compressed-image.jpg
-quality 80
: Sets the output quality to 80%. Lowering the number reduces file size.-resize 1024x768
: Resizes the image to a maximum of 1024×768 pixels (adjust as needed).
Repeat the command with lower quality until the file is under 100 KB.
3. Using ffmpeg
ffmpeg
is a powerful multimedia tool that can compress images by reducing the quality.
Install ffmpeg
:
sudo apt-get install ffmpeg # For Debian/Ubuntu
sudo dnf install ffmpeg # For Fedora
sudo yum install ffmpeg # For CentOS/RHEL
Compress the JPG File:
ffmpeg -i your-image.jpg -q:v 31 compressed-image.jpg
-q:v 31
: Sets the compression quality (ranges from 2 to 31). Increase this number to reduce file size more significantly.
4. Checking the File Size
After compression, check the file size:
ls -lh compressed-image.jpg
If the file is still over 100 KB, try reducing the quality or resizing further with any of the tools.
Additional Tips:
- Iterative Adjustment: Start with higher quality settings and gradually reduce them until you achieve the desired file size.
- Combine Techniques: Use a combination of resizing and quality reduction to reach the target size while maintaining the best visual quality.
Feature photo by Godwin Angeline Benjo on Unsplash