{"id":78958,"date":"2026-04-15T14:06:45","date_gmt":"2026-04-15T08:36:45","guid":{"rendered":"https:\/\/2thenew.xyz\/blog\/?p=78958"},"modified":"2026-04-22T11:27:42","modified_gmt":"2026-04-22T05:57:42","slug":"building-a-python-file-compressor-with-ghostscript-and-pillow","status":"publish","type":"post","link":"https:\/\/2thenew.xyz\/blog\/building-a-python-file-compressor-with-ghostscript-and-pillow\/","title":{"rendered":"Building a Python File Compressor with Ghostscript and Pillow"},"content":{"rendered":"<h2><span style=\"font-size: 1.5rem;\">Building a Production\u2011Grade File Compression Utility in Python<\/span><\/h2>\n<article>We built an open\u2011source Python tool that shrinks 30\u201350 MB PDFs and images down to under 2 MB \u2014 with readable output, a desktop GUI, Docker support, CLI, and a one\u2011click <code>.exe<\/code> build. This post explains how it works under the hood.<\/p>\n<h2>The Problem Nobody Talks About<\/h2>\n<p>Every organization has the same quiet pain point: <strong>oversized files<\/strong>.<\/p>\n<ul>\n<li>A 42 MB scanned contract that won\u2019t attach to an email<\/li>\n<li>A folder of 35 MB site photos that choke a web upload form<\/li>\n<li>A SharePoint library ballooning because nobody compresses before uploading<\/li>\n<\/ul>\n<p>Online compressors cap uploads, destroy quality, or charge monthly fees.<br \/>\nManual Ghostscript commands? Great \u2014 if you memorize flags for a living.<\/p>\n<p>We needed something that just works:<br \/>\n<strong>target a size, hit compress, done.<\/strong><\/p>\n<h2>What This Utility Does<\/h2>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"8\">\n<thead>\n<tr>\n<th>Capability<\/th>\n<th>Details<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Image compression<\/td>\n<td>JPEG, PNG, TIFF, BMP, WebP \u2192 optimized JPEG<\/td>\n<\/tr>\n<tr>\n<td>PDF compression<\/td>\n<td>Ghostscript (primary), raster pipeline, pikepdf fallback<\/td>\n<\/tr>\n<tr>\n<td>Precision targeting<\/td>\n<td>Set an exact target size (e.g. 1.8 MB)<\/td>\n<\/tr>\n<tr>\n<td>Scanned PDF intelligence<\/td>\n<td>Auto\u2011detects text vs scanned pages<\/td>\n<\/tr>\n<tr>\n<td>Batch processing<\/td>\n<td>Parallel directory compression<\/td>\n<\/tr>\n<tr>\n<td>Desktop GUI<\/td>\n<td>Tkinter-based Upload \u2192 Compress \u2192 Download workflow<\/td>\n<\/tr>\n<tr>\n<td>CLI<\/td>\n<td>Click-powered command-line interface<\/td>\n<\/tr>\n<tr>\n<td>Docker<\/td>\n<td>Preconfigured image with system dependencies<\/td>\n<\/tr>\n<tr>\n<td>Standalone .exe<\/td>\n<td>PyInstaller build for zero-install distribution<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>Real\u2011World Compression Results<\/h2>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"8\">\n<thead>\n<tr>\n<th>File Type<\/th>\n<th>Input Size<\/th>\n<th>Output Size<\/th>\n<th>Reduction<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Images<\/td>\n<td>30\u201350 MB<\/td>\n<td>~500 KB<\/td>\n<td>~98%<\/td>\n<\/tr>\n<tr>\n<td>PDFs<\/td>\n<td>30\u201350 MB<\/td>\n<td>~1.8 MB<\/td>\n<td>~96%<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>A 42 MB scanned PDF becomes a crisp <strong>1.7 MB<\/strong> file that remains perfectly readable.<\/p>\n<h2>Architecture Overview<\/h2>\n<pre><code>\r\nsrc\/\r\n\u251c\u2500\u2500 compressor.py\r\n\u251c\u2500\u2500 image_compressor.py\r\n\u251c\u2500\u2500 pdf_compressor.py\r\n\u251c\u2500\u2500 config.py\r\n\u2514\u2500\u2500 utils.py\r\n\r\nmain.py\r\ncompression_service.py\r\nui_app.py\r\nui_actions.py\r\nui_styles.py\r\nstate.py\r\n  <\/code><\/pre>\n<p>The key design decision:<br \/>\n<strong>one compression core<\/strong>.<br \/>\nBoth the CLI and GUI call <code>compress_core()<\/code>.<br \/>\nNo duplicated logic. No divergence.<\/p>\n<h2>How the Image Pipeline Works<\/h2>\n<ol>\n<li><strong>Load &amp; Analyze<\/strong> \u2014 dimensions, mode, alpha channel<\/li>\n<li><strong>Pre\u2011process<\/strong> \u2014 RGB conversion, alpha compositing<\/li>\n<li><strong>Resize<\/strong> \u2014 proportional downscale using LANCZOS<\/li>\n<li><strong>Optimize<\/strong> \u2014 dual\u2011axis quality + dimension tuning<\/li>\n<li><strong>Validate<\/strong> \u2014 verify size and compression ratio<\/li>\n<\/ol>\n<p>This two\u2011axis approach (quality + dimensions) enables aggressive targets<br \/>\nlike <strong>500 KB from a 40 MB image<\/strong> without turning it into mush.<\/p>\n<h2>How the PDF Pipeline Works<\/h2>\n<h3>Strategy 1: Ghostscript<\/h3>\n<pre><code>\r\ngs -sDEVICE=pdfwrite\r\n   -dCompatibilityLevel=1.4\r\n   -dPDFSETTINGS=\/ebook\r\n   -dColorImageResolution=120\r\n   -dDownsampleColorImages=true\r\n   -sOutputFile=output.pdf\r\n   input.pdf\r\n  <\/code><\/pre>\n<p>Presets and DPI values are tried in descending quality order until the target is met.<\/p>\n<h3>Strategy 2: Raster Pipeline<\/h3>\n<ul>\n<li>Render pages via pdf2image<\/li>\n<li>Enhance contrast and sharpness (OpenCV)<\/li>\n<li>Binary\u2011search JPEG quality<\/li>\n<li>Rebuild PDF via img2pdf<\/li>\n<\/ul>\n<h3>Strategy 3: Auto\u2011Detection<\/h3>\n<p>Text pages are preserved. Scanned pages are raster\u2011compressed.<br \/>\nOptional region\u2011aware compression preserves text while shrinking photos.<\/p>\n<h3>Strategy 4: pikepdf Fallback<\/h3>\n<p>When all else fails, basic stream compression ensures some reduction.<\/p>\n<hr \/>\n<h2>The Desktop GUI<\/h2>\n<p>A Tkinter-based interface with a simple workflow:<br \/>\n<strong>Upload \u2192 Compress \u2192 Download<\/strong><\/p>\n<ul>\n<li>Threaded background compression<\/li>\n<li>KB \/ MB target selector<\/li>\n<li>Temp file safety (no overwrites)<\/li>\n<li>Minimal state management<\/li>\n<\/ul>\n<hr \/>\n<h2>The CLI<\/h2>\n<pre><code>\r\npython main.py compress document.pdf --target-size 1800\r\npython main.py compress-dir input\/ --target-size 500 --workers 8\r\npython main.py analyze document.pdf\r\npython main.py check\r\n  <\/code><\/pre>\n<hr \/>\n<h2>Using It as a Python Library<\/h2>\n<pre><code>\r\nfrom src.compressor import FileCompressor\r\n\r\ncompressor = FileCompressor(target_size_kb=1800)\r\nresult = compressor.compress(\"input.pdf\", \"output.pdf\")\r\n  <\/code><\/pre>\n<h2>Lessons Learned<\/h2>\n<ul>\n<li>Binary search beats linear quality stepping<\/li>\n<li>Two\u2011axis optimization is essential<\/li>\n<li>Scanned PDFs need raster treatment<\/li>\n<li>Ghostscript discovery on Windows is non\u2011trivial<\/li>\n<li>Temp outputs prevent accidental data loss<\/li>\n<\/ul>\n<hr \/>\n<h2>Getting Started<\/h2>\n<pre><code>\r\npip install -r requirements.txt\r\npython main.py compress large.pdf --target-size 1800\r\n  <\/code><\/pre>\n<p>Built with Python, Ghostscript, Pillow, and a healthy frustration with file size limits.<\/p>\n<\/article>\n","protected":false},"excerpt":{"rendered":"<p>Building a Production\u2011Grade File Compression Utility in Python We built an open\u2011source Python tool that shrinks 30\u201350 MB PDFs and images down to under 2 MB \u2014 with readable output, a desktop GUI, Docker support, CLI, and a one\u2011click .exe build. This post explains how it works under the hood. The Problem Nobody Talks About [&hellip;]<\/p>\n","protected":false},"author":2246,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":61,"footnotes":""},"categories":[5879],"tags":[8512,8513,1358],"class_list":["post-78958","post","type-post","status-publish","format-standard","hentry","category-python","tag-ghostscript","tag-pillow","tag-python"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"Building a Production\u2011Grade File Compression Utility in Python We built an open\u2011source Python tool that shrinks 30\u201350 MB PDFs and images down to under 2 MB \u2014 with readable output, a desktop GUI, Docker support, CLI, and a one\u2011click .exe build. This post explains how it works under the hood. The Problem Nobody Talks About\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Shubham Agrawal\"\/>\n\t<link rel=\"canonical\" href=\"https:\/\/2thenew.xyz\/blog\/building-a-python-file-compressor-with-ghostscript-and-pillow\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"TO THE NEW BLOG\" \/>\n\t\t<meta property=\"og:type\" content=\"blog\" \/>\n\t\t<meta property=\"og:title\" content=\"Building a Python File Compressor with Ghostscript and Pillow | TO THE NEW Blog\" \/>\n\t\t<meta property=\"og:description\" content=\"Building a Production\u2011Grade File Compression Utility in Python We built an open\u2011source Python tool that shrinks 30\u201350 MB PDFs and images down to under 2 MB \u2014 with readable output, a desktop GUI, Docker support, CLI, and a one\u2011click .exe build. This post explains how it works under the hood. The Problem Nobody Talks About\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/2thenew.xyz\/blog\/building-a-python-file-compressor-with-ghostscript-and-pillow\/\" \/>\n\t\t<meta property=\"og:image\" content=\"https:\/\/2thenew.xyz\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta property=\"og:image:secure_url\" content=\"https:\/\/2thenew.xyz\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:site\" content=\"@tothenew\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Building a Python File Compressor with Ghostscript and Pillow | TO THE NEW Blog\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Building a Production\u2011Grade File Compression Utility in Python We built an open\u2011source Python tool that shrinks 30\u201350 MB PDFs and images down to under 2 MB \u2014 with readable output, a desktop GUI, Docker support, CLI, and a one\u2011click .exe build. This post explains how it works under the hood. The Problem Nobody Talks About\" \/>\n\t\t<meta name=\"twitter:image\" content=\"https:\/\/2thenew.xyz\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/building-a-python-file-compressor-with-ghostscript-and-pillow\\\/#article\",\"name\":\"Building a Python File Compressor with Ghostscript and Pillow | TO THE NEW Blog\",\"headline\":\"Building a Python File Compressor with Ghostscript and Pillow\",\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/shubham-agrawal\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"},\"datePublished\":\"2026-04-15T14:06:45+05:30\",\"dateModified\":\"2026-04-22T11:27:42+05:30\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/building-a-python-file-compressor-with-ghostscript-and-pillow\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/building-a-python-file-compressor-with-ghostscript-and-pillow\\\/#webpage\"},\"articleSection\":\"Python, Ghostscript, Pillow, python\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/building-a-python-file-compressor-with-ghostscript-and-pillow\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/python\\\/#listItem\",\"name\":\"Python\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/python\\\/#listItem\",\"position\":2,\"name\":\"Python\",\"item\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/python\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/building-a-python-file-compressor-with-ghostscript-and-pillow\\\/#listItem\",\"name\":\"Building a Python File Compressor with Ghostscript and Pillow\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/building-a-python-file-compressor-with-ghostscript-and-pillow\\\/#listItem\",\"position\":3,\"name\":\"Building a Python File Compressor with Ghostscript and Pillow\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/category\\\/python\\\/#listItem\",\"name\":\"Python\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\",\"name\":\"TO THE NEW Blog\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/shubham-agrawal\\\/#author\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/shubham-agrawal\\\/\",\"name\":\"Shubham Agrawal\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/building-a-python-file-compressor-with-ghostscript-and-pillow\\\/#authorImage\",\"url\":\"https:\\\/\\\/newersworld-sf-static.tothenew.net\\\/prod\\\/profilePicFolder\\\/c3de2a52-8074-4f25-b6aa-a642c6fd39f5_Shubham-Agrawal-Profile-Pitcure.jpeg\",\"width\":96,\"height\":96,\"caption\":\"Shubham Agrawal\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/building-a-python-file-compressor-with-ghostscript-and-pillow\\\/#webpage\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/building-a-python-file-compressor-with-ghostscript-and-pillow\\\/\",\"name\":\"Building a Python File Compressor with Ghostscript and Pillow | TO THE NEW Blog\",\"description\":\"Building a Production\\u2011Grade File Compression Utility in Python We built an open\\u2011source Python tool that shrinks 30\\u201350 MB PDFs and images down to under 2 MB \\u2014 with readable output, a desktop GUI, Docker support, CLI, and a one\\u2011click .exe build. This post explains how it works under the hood. The Problem Nobody Talks About\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/building-a-python-file-compressor-with-ghostscript-and-pillow\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/shubham-agrawal\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/author\\\/shubham-agrawal\\\/#author\"},\"datePublished\":\"2026-04-15T14:06:45+05:30\",\"dateModified\":\"2026-04-22T11:27:42+05:30\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/\",\"name\":\"TO THE NEW Blog\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.tothenew.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Building a Python File Compressor with Ghostscript and Pillow | TO THE NEW Blog","description":"Building a Production\u2011Grade File Compression Utility in Python We built an open\u2011source Python tool that shrinks 30\u201350 MB PDFs and images down to under 2 MB \u2014 with readable output, a desktop GUI, Docker support, CLI, and a one\u2011click .exe build. This post explains how it works under the hood. The Problem Nobody Talks About","canonical_url":"https:\/\/2thenew.xyz\/blog\/building-a-python-file-compressor-with-ghostscript-and-pillow\/","robots":"max-image-preview:large","keywords":"","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/2thenew.xyz\/blog\/building-a-python-file-compressor-with-ghostscript-and-pillow\/#article","name":"Building a Python File Compressor with Ghostscript and Pillow | TO THE NEW Blog","headline":"Building a Python File Compressor with Ghostscript and Pillow","author":{"@id":"https:\/\/2thenew.xyz\/blog\/author\/shubham-agrawal\/#author"},"publisher":{"@id":"https:\/\/2thenew.xyz\/blog\/#organization"},"datePublished":"2026-04-15T14:06:45+05:30","dateModified":"2026-04-22T11:27:42+05:30","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/2thenew.xyz\/blog\/building-a-python-file-compressor-with-ghostscript-and-pillow\/#webpage"},"isPartOf":{"@id":"https:\/\/2thenew.xyz\/blog\/building-a-python-file-compressor-with-ghostscript-and-pillow\/#webpage"},"articleSection":"Python, Ghostscript, Pillow, python"},{"@type":"BreadcrumbList","@id":"https:\/\/2thenew.xyz\/blog\/building-a-python-file-compressor-with-ghostscript-and-pillow\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog#listItem","position":1,"name":"Home","item":"https:\/\/2thenew.xyz\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog\/category\/python\/#listItem","name":"Python"}},{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog\/category\/python\/#listItem","position":2,"name":"Python","item":"https:\/\/2thenew.xyz\/blog\/category\/python\/","nextItem":{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog\/building-a-python-file-compressor-with-ghostscript-and-pillow\/#listItem","name":"Building a Python File Compressor with Ghostscript and Pillow"},"previousItem":{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog\/building-a-python-file-compressor-with-ghostscript-and-pillow\/#listItem","position":3,"name":"Building a Python File Compressor with Ghostscript and Pillow","previousItem":{"@type":"ListItem","@id":"https:\/\/2thenew.xyz\/blog\/category\/python\/#listItem","name":"Python"}}]},{"@type":"Organization","@id":"https:\/\/2thenew.xyz\/blog\/#organization","name":"TO THE NEW Blog","url":"https:\/\/2thenew.xyz\/blog\/"},{"@type":"Person","@id":"https:\/\/2thenew.xyz\/blog\/author\/shubham-agrawal\/#author","url":"https:\/\/2thenew.xyz\/blog\/author\/shubham-agrawal\/","name":"Shubham Agrawal","image":{"@type":"ImageObject","@id":"https:\/\/2thenew.xyz\/blog\/building-a-python-file-compressor-with-ghostscript-and-pillow\/#authorImage","url":"https:\/\/newersworld-sf-static.tothenew.net\/prod\/profilePicFolder\/c3de2a52-8074-4f25-b6aa-a642c6fd39f5_Shubham-Agrawal-Profile-Pitcure.jpeg","width":96,"height":96,"caption":"Shubham Agrawal"}},{"@type":"WebPage","@id":"https:\/\/2thenew.xyz\/blog\/building-a-python-file-compressor-with-ghostscript-and-pillow\/#webpage","url":"https:\/\/2thenew.xyz\/blog\/building-a-python-file-compressor-with-ghostscript-and-pillow\/","name":"Building a Python File Compressor with Ghostscript and Pillow | TO THE NEW Blog","description":"Building a Production\u2011Grade File Compression Utility in Python We built an open\u2011source Python tool that shrinks 30\u201350 MB PDFs and images down to under 2 MB \u2014 with readable output, a desktop GUI, Docker support, CLI, and a one\u2011click .exe build. This post explains how it works under the hood. The Problem Nobody Talks About","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/2thenew.xyz\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/2thenew.xyz\/blog\/building-a-python-file-compressor-with-ghostscript-and-pillow\/#breadcrumblist"},"author":{"@id":"https:\/\/2thenew.xyz\/blog\/author\/shubham-agrawal\/#author"},"creator":{"@id":"https:\/\/2thenew.xyz\/blog\/author\/shubham-agrawal\/#author"},"datePublished":"2026-04-15T14:06:45+05:30","dateModified":"2026-04-22T11:27:42+05:30"},{"@type":"WebSite","@id":"https:\/\/2thenew.xyz\/blog\/#website","url":"https:\/\/2thenew.xyz\/blog\/","name":"TO THE NEW Blog","inLanguage":"en-US","publisher":{"@id":"https:\/\/2thenew.xyz\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"TO THE NEW BLOG","og:type":"blog","og:title":"Building a Python File Compressor with Ghostscript and Pillow | TO THE NEW Blog","og:description":"Building a Production\u2011Grade File Compression Utility in Python We built an open\u2011source Python tool that shrinks 30\u201350 MB PDFs and images down to under 2 MB \u2014 with readable output, a desktop GUI, Docker support, CLI, and a one\u2011click .exe build. This post explains how it works under the hood. The Problem Nobody Talks About","og:url":"https:\/\/2thenew.xyz\/blog\/building-a-python-file-compressor-with-ghostscript-and-pillow\/","og:image":"https:\/\/2thenew.xyz\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","og:image:secure_url":"https:\/\/2thenew.xyz\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png","twitter:card":"summary","twitter:site":"@tothenew","twitter:title":"Building a Python File Compressor with Ghostscript and Pillow | TO THE NEW Blog","twitter:description":"Building a Production\u2011Grade File Compression Utility in Python We built an open\u2011source Python tool that shrinks 30\u201350 MB PDFs and images down to under 2 MB \u2014 with readable output, a desktop GUI, Docker support, CLI, and a one\u2011click .exe build. This post explains how it works under the hood. The Problem Nobody Talks About","twitter:image":"https:\/\/2thenew.xyz\/blog\/wp-content\/themes\/ttn\/images\/social-logo.png"},"aioseo_meta_data":{"post_id":"78958","title":null,"description":null,"keywords":[],"keyphrases":{"focus":{"keyphrase":"","score":0,"analysis":{"keyphraseInTitle":{"score":0,"maxScore":9,"error":1}}},"additional":[]},"primary_term":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_url":null,"og_image_width":null,"og_image_height":null,"og_image_custom_url":null,"og_image_custom_fields":null,"og_video":"","og_custom_url":null,"og_article_section":null,"og_article_tags":[],"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_url":null,"twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"schema_type":"default","schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":"-1","robots_max_videopreview":"-1","robots_max_imagepreview":"large","priority":null,"frequency":"default","local_seo":null,"limit_modified_date":false,"created":"2026-03-22 15:51:15","updated":"2026-04-22 05:57:43","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/2thenew.xyz\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/2thenew.xyz\/blog\/category\/python\/\" title=\"Python\">Python<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tBuilding a Python File Compressor with Ghostscript and Pillow\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/2thenew.xyz\/blog"},{"label":"Python","link":"https:\/\/2thenew.xyz\/blog\/category\/python\/"},{"label":"Building a Python File Compressor with Ghostscript and Pillow","link":"https:\/\/2thenew.xyz\/blog\/building-a-python-file-compressor-with-ghostscript-and-pillow\/"}],"_links":{"self":[{"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/posts\/78958","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/users\/2246"}],"replies":[{"embeddable":true,"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/comments?post=78958"}],"version-history":[{"count":2,"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/posts\/78958\/revisions"}],"predecessor-version":[{"id":79669,"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/posts\/78958\/revisions\/79669"}],"wp:attachment":[{"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/media?parent=78958"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/categories?post=78958"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/2thenew.xyz\/blog\/wp-json\/wp\/v2\/tags?post=78958"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}