{"id":181,"date":"2024-09-09T12:50:00","date_gmt":"2024-09-09T16:50:00","guid":{"rendered":"\/blog\/?p=181"},"modified":"2024-09-08T12:57:11","modified_gmt":"2024-09-08T16:57:11","slug":"how-to-compress-a-jpg-file-to-100-kb-in-linux","status":"publish","type":"post","link":"\/blog\/how-to-compress-a-jpg-file-to-100-kb-in-linux","title":{"rendered":"How to compress a JPG file to 100 KB in Linux?"},"content":{"rendered":"\n<p>To compress a JPG file to exactly or under 100 KB in Linux, you can use tools like <code>jpegoptim<\/code>, <code>convert<\/code> (from ImageMagick), or <code>ffmpeg<\/code>. Here is a detailed guide on how to use these tools effectively:<\/p>\n\n\n\n<p>Before we begin, we want to let you know you can use\u00a0<a href=\"https:\/\/www.xconvert.com\/compress-jpeg\">https:\/\/www.xconvert.com\/compress-jpeg<\/a>\u00a0to compress your JPG\/JPEG to 100KB online. You can choose\u00a0<code>Autoscale<\/code>\u00a0feature to keep the quality high while reducing file size to less than 100KB.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">1. <strong>Using <code>jpegoptim<\/code><\/strong><\/h3>\n\n\n\n<p><code>jpegoptim<\/code> is a tool designed to optimize and compress JPEG files, either with or without quality loss. You can specify a target size and let <code>jpegoptim<\/code> handle the compression.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Install <code>jpegoptim<\/code>:<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">sudo apt-get install jpegoptim   # For Debian\/Ubuntu\nsudo dnf install jpegoptim       # For Fedora\nsudo yum install jpegoptim       # For CentOS\/RHEL<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Compress the JPG File:<\/h4>\n\n\n\n<p>To reduce the file size while maintaining acceptable quality:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">jpegoptim --size=100k your-image.jpg<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>--size=100k<\/code>: Sets the target size to 100 KB. <code>jpegoptim<\/code> will adjust the compression level to meet this target.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. <strong>Using <code>convert<\/code> from ImageMagick<\/strong><\/h3>\n\n\n\n<p><code>convert<\/code> from ImageMagick is versatile for image manipulation, including adjusting quality and resizing to achieve the desired file size.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Install ImageMagick:<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">sudo apt-get install imagemagick   # For Debian\/Ubuntu\nsudo dnf install imagemagick       # For Fedora\nsudo yum install imagemagick       # For CentOS\/RHEL<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Compress the JPG File:<\/h4>\n\n\n\n<p>Since ImageMagick doesn\u2019t directly allow specifying a target size, you may need to adjust the quality iteratively:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">convert your-image.jpg -quality 80 -resize 1024x768 compressed-image.jpg<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>-quality 80<\/code>: Sets the output quality to 80%. Lowering the number reduces file size.<\/li>\n\n\n\n<li><code>-resize 1024x768<\/code>: Resizes the image to a maximum of 1024&#215;768 pixels (adjust as needed).<\/li>\n<\/ul>\n\n\n\n<p>Repeat the command with lower quality until the file is under 100 KB.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. <strong>Using <code>ffmpeg<\/code><\/strong><\/h3>\n\n\n\n<p><code>ffmpeg<\/code> is a powerful multimedia tool that can compress images by reducing the quality.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Install <code>ffmpeg<\/code>:<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">sudo apt-get install ffmpeg   # For Debian\/Ubuntu\nsudo dnf install ffmpeg       # For Fedora\nsudo yum install ffmpeg       # For CentOS\/RHEL<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Compress the JPG File:<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">ffmpeg -i your-image.jpg -q:v 31 compressed-image.jpg<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>-q:v 31<\/code>: Sets the compression quality (ranges from 2 to 31). Increase this number to reduce file size more significantly.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">4. <strong>Checking the File Size<\/strong><\/h3>\n\n\n\n<p>After compression, check the file size:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">ls -lh compressed-image.jpg<\/code><\/pre>\n\n\n\n<p>If the file is still over 100 KB, try reducing the quality or resizing further with any of the tools.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Additional Tips:<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Iterative Adjustment:<\/strong> Start with higher quality settings and gradually reduce them until you achieve the desired file size.<\/li>\n\n\n\n<li><strong>Combine Techniques:<\/strong> Use a combination of resizing and quality reduction to reach the target size while maintaining the best visual quality.<\/li>\n<\/ul>\n\n\n\n<p>Feature photo by <a href=\"https:\/\/unsplash.com\/@gabography?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash\">Godwin Angeline Benjo<\/a> on <a href=\"https:\/\/unsplash.com\/photos\/black-yamaha-motorcycle-gauge-wsMYnBXxntM?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash\">Unsplash<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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\u00a0https:\/\/www.xconvert.com\/compress-jpeg\u00a0to compress your JPG\/JPEG to 100KB online. You [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":182,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,4],"tags":[10,9,11,12],"class_list":["post-181","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-how-to-guides","category-tutorial","tag-compress-image","tag-compress-jpg","tag-file-compression","tag-reduce-image-size"],"_links":{"self":[{"href":"\/blog\/wp-json\/wp\/v2\/posts\/181","targetHints":{"allow":["GET"]}}],"collection":[{"href":"\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"\/blog\/wp-json\/wp\/v2\/comments?post=181"}],"version-history":[{"count":2,"href":"\/blog\/wp-json\/wp\/v2\/posts\/181\/revisions"}],"predecessor-version":[{"id":185,"href":"\/blog\/wp-json\/wp\/v2\/posts\/181\/revisions\/185"}],"wp:featuredmedia":[{"embeddable":true,"href":"\/blog\/wp-json\/wp\/v2\/media\/182"}],"wp:attachment":[{"href":"\/blog\/wp-json\/wp\/v2\/media?parent=181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"\/blog\/wp-json\/wp\/v2\/categories?post=181"},{"taxonomy":"post_tag","embeddable":true,"href":"\/blog\/wp-json\/wp\/v2\/tags?post=181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}