{"id":21895,"date":"2019-06-05T15:27:14","date_gmt":"2019-06-05T15:27:14","guid":{"rendered":"http:\/\/compression_of_image_files_with_only_one_line_of_code"},"modified":"2025-03-09T13:10:55","modified_gmt":"2025-03-09T20:10:55","slug":"compression_of_image_files_with_only_one_line_of_code","status":"publish","type":"post","link":"https:\/\/cloudinary.com\/blog\/compression_of_image_files_with_only_one_line_of_code","title":{"rendered":"Compression of Image Files With Only One Line of Code"},"content":{"rendered":"<div class=\"wp-block-cloudinary-markdown \"><p>I recently came across a tweet by organizer and developer advocate <a href=\"https:\/\/twitter.com\/iChuloo\">iChuloo<\/a> by way of <a href=\"https:\/\/twitter.com\/jamstacklagos\">@JAMStackLagos<\/a> on how to <a href=\"https:\/\/cloudinary.com\/features\/optimization_fast_delivery\">reduce the size of an image<\/a> with only one line of code on <a href=\"https:\/\/cloudinary.com\/products\/programmable_media\">Cloudinary<\/a>.<\/p>\n<blockquote class=\"twitter-tweet\" data-lang=\"en\"><p lang=\"en\" dir=\"ltr\">Using <a href=\"https:\/\/twitter.com\/cloudinary?ref_src=twsrc%5Etfw\">@cloudinary<\/a> in React and this sends the image size down by ~88% with no visible change in quality. Holy smokes!! <a href=\"https:\/\/t.co\/PT2b3785Lo\">pic.twitter.com\/PT2b3785Lo<\/a><\/p>&mdash; William Imoh (@iChuloo) <a href=\"https:\/\/twitter.com\/iChuloo\/status\/1121883178594119681?ref_src=twsrc%5Etfw\">April 26, 2019<\/a><\/blockquote>\n<script async src=\"https:\/\/platform.twitter.com\/widgets.js\" charset=\"utf-8\"><\/script>\n<p>That tweet rang a bell. I then recalled that I\u2019d used that exact codeline in at least two <a href=\"https:\/\/reactjs.org\/\">React<\/a> projects in the past.<\/p>\n<p>This article digs deeper, showing you how to compress image files, again with one line of code, in PHP, Java, or Python on environments or frameworks like React, Node, Vue, and Angular.<\/p>\n<h2>Image Compression<\/h2>\n<p>As a rule, compression of image files are either for storage or for delivery.<\/p>\n<h3>Image Storage<\/h3>\n<p>The compression of image files for cloud storage when requesting their upload to Cloudinary. Subsequently, Cloudinary applies to the files the transformations you specified before storing them. The examples below show the codeline in Ruby, Python, PHP, and Java. You can also code in a similar manner in other modern languages.<\/p>\n<p><em>Ruby<\/em><\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\">Cloudinary::Uploader.upload(<span class=\"hljs-string\">\"cat.jpg\"<\/span>, :<span class=\"hljs-function\"><span class=\"hljs-params\">quality<\/span> =&gt;<\/span> <span class=\"hljs-number\">60<\/span>)\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p><em>Python<\/em><\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\">cloudinary.uploader.upload(<span class=\"hljs-string\">\"cat.jpg\"<\/span>, <span class=\"hljs-string\">\"quality\"<\/span> = <span class=\"hljs-string\">\"60\"<\/span>)\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p><em>PHP<\/em><\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php shcb-wrap-lines\">\\Cloudinary\\Uploader::upload(<span class=\"hljs-string\">\"cat.jpg\"<\/span>, &#91; <span class=\"hljs-string\">\"quality\"<\/span> =&gt; <span class=\"hljs-string\">\"60\"<\/span>]);\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p><em>Java<\/em><\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css shcb-wrap-lines\"><span class=\"hljs-selector-tag\">cloudinary<\/span><span class=\"hljs-selector-class\">.url<\/span>()<span class=\"hljs-selector-class\">.transformation<\/span>(<span class=\"hljs-selector-tag\">new<\/span> <span class=\"hljs-selector-tag\">Transformation<\/span>()<span class=\"hljs-selector-class\">.quality<\/span>(60))<span class=\"hljs-selector-class\">.imageTag<\/span>(\"<span class=\"hljs-selector-tag\">cat<\/span><span class=\"hljs-selector-class\">.jpg<\/span>\");\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p>In the code above, <code>quality<\/code> is a compression parameter that specifies the image quality and size for storage. If you\u2019re not sure what number to assign to <code>quality<\/code>, just type <code>auto<\/code>. Cloudinary then automatically adjusts the compression quality for your image by applying the optimal balance between the image\u2019s file size and quality.<\/p>\n<h3>Image Delivery<\/h3>\n<p>In this context, you upload images straight to the cloud and then apply the <code>quality<\/code> compression parameter when delivering them to users. You can also serve images in the <a href=\"https:\/\/cloudinary.com\/documentation\/image_transformations#image_format_support\">formats that pertain to the various web browsers and mobile devices<\/a>.<\/p>\n<p>You configure quality on a <strong>0-100<\/strong> scale. The higher the image quality, the larger the image size; the lower the image quality, the smaller the image size. To compress images on the fly, adjust their <code>quality<\/code> parameter. See the examples below.<\/p>\n<p><em>Node.js<\/em><\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css shcb-wrap-lines\"><span class=\"hljs-selector-tag\">cloudinary<\/span><span class=\"hljs-selector-class\">.image<\/span>(\"<span class=\"hljs-selector-tag\">cat<\/span>\", {<span class=\"hljs-attribute\">quality<\/span>: <span class=\"hljs-number\">50<\/span>})\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p><em>Java<\/em><\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css shcb-wrap-lines\"><span class=\"hljs-selector-tag\">cloudinary<\/span><span class=\"hljs-selector-class\">.url<\/span>()<span class=\"hljs-selector-class\">.transformation<\/span>(<span class=\"hljs-selector-tag\">new<\/span> <span class=\"hljs-selector-tag\">Transformation<\/span>()<span class=\"hljs-selector-class\">.quality<\/span>(50))<span class=\"hljs-selector-class\">.imageTag<\/span>(\"<span class=\"hljs-selector-tag\">cat<\/span>\");\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p><em>Python<\/em><\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\">CloudinaryImage(<span class=\"hljs-string\">\"dog\"<\/span>).image(quality=cat)\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<hr \/>\n<p>Alternatively, simply add a <code>q<\/code> parameter to your image\u2019s URL, for example:<\/p>\n<pre class=\"js-syntax-highlighted\"><code>https:\/\/res.cloudinary.com\/demo\/image\/upload\/q_50\/cat.jpg\n<\/code><\/pre>\n<p>Here, <code>q<\/code> stands for quality; <code>50<\/code> is your choice on a 0-100 scale.<\/p>\n<hr \/>\n<p>Front-end developers can drop the components in their app out of the box, like this:<\/p>\n<p><em>React.js<\/em><\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml shcb-wrap-lines\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Image<\/span> <span class=\"hljs-attr\">publicId<\/span>=<span class=\"hljs-string\">\"cat.jpg\"<\/span> &gt;<\/span><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Transformation<\/span> <span class=\"hljs-attr\">quality<\/span>=<span class=\"hljs-string\">\"50\"<\/span> \/&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Image<\/span>&gt;<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p><em>Vue.js<\/em><\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml shcb-wrap-lines\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">cld-image<\/span> <span class=\"hljs-attr\">publicId<\/span>=<span class=\"hljs-string\">\"cat.jpg\"<\/span> &gt;<\/span><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">cld-transformation<\/span> <span class=\"hljs-attr\">quality<\/span>=<span class=\"hljs-string\">\"50\"<\/span> \/&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">cld-image<\/span>&gt;<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p><em>Angular<\/em><\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml shcb-wrap-lines\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">cl-image<\/span> <span class=\"hljs-attr\">public-id<\/span>=<span class=\"hljs-string\">\"cat.jpg\"<\/span> &gt;<\/span><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">cl-transformation<\/span> <span class=\"hljs-attr\">quality<\/span>=<span class=\"hljs-string\">\"50\"<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">cl-transformation<\/span>&gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">cl-image<\/span>&gt;<\/span>\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">HTML, XML<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">xml<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p><em>JQuery<\/em><\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\">$.cloudinary.image(<span class=\"hljs-string\">\"cat.jpg\"<\/span>, {<span class=\"hljs-attr\">quality<\/span>: <span class=\"hljs-number\">50<\/span>})\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p><em>JavaScript<\/em><\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\">cloudinary.imageTag(<span class=\"hljs-string\">'cat.jpg'<\/span>, {<span class=\"hljs-attr\">quality<\/span>: <span class=\"hljs-number\">50<\/span>}).toHtml();\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n<p>Here, <code>cat<\/code> is the name of the uploaded image, which is usually the public ID (<code>publicId<\/code>) on the Cloudinary storage platform.<\/p>\n<h2>Conclusion<\/h2>\n<p>Uploading without images optimization or compression wastes bandwidth. Plus, delivering them on your app invariably takes longer. Why not automate the compression process with Cloudinary\u2019s effective and simple drop-in tools so that your visuals load fast?<\/p>\n<p><a href=\"https:\/\/cloudinary.com\/users\/register\/free\">Register for free<\/a> and for more details, check out the following Cloudinary documentation:<\/p>\n<ul>\n<li>\n<a href=\"https:\/\/cloudinary.com\/documentation\/image_optimization\">Image optimization<\/a>\n<\/li>\n<li>\n<a href=\"https:\/\/cloudinary.com\/documentation\/cloudinary_sdks\">SDKs and libraries: server sde, client side, and mobile<\/a>\n<\/li>\n<\/ul>\n<hr \/>\n<h2>Further Reading on Image Optimization<\/h2>\n<ul>\n<li>\n<a href=\"https:\/\/cloudinary.com\/blog\/image_optimization_for_websites_beautiful_pages_that_load_quickly\">Website image optimization and fast delivery with Cloudinary<\/a>\n<\/li>\n<li>\n<a href=\"https:\/\/cloudinary.com\/blog\/image_optimization_in_php\">The complete guide to PHP image compression and optimization<\/a>\n<\/li>\n<li>\n<a href=\"https:\/\/cloudinary.com\/blog\/vue_js_tutorial_image_optimization_for_web_apps\">Vue.js Tutorial: Images Optimization for Web Apps<\/a>\n<\/li>\n<li>\n<a href=\"https:\/\/cloudinary.com\/blog\/image_optimization_in_python\">Python Image Optimization and Manipulation<\/a>\n<\/li>\n<li>\n<a href=\"https:\/\/cloudinary.com\/blog\/image_optimization_in_ruby\">Image Optimization in Ruby<\/a>\n<\/li>\n<li>\n<a href=\"https:\/\/cloudinary.com\/blog\/image_optimization_in_wordpress\">Image Optimization for WordPress<\/a>\n<\/li>\n<li>\n<a href=\"https:\/\/cloudinary.com\/blog\/the_great_jpeg_2000_debate_analyzing_the_pros_and_cons_to_widespread_adoption\">Learn about the pros and cons of JPEG 2000<\/a>\n<\/li>\n<li>\n<a href=\"https:\/\/cloudinary.com\/blog\/quick_guide_using_webp_on_your_website_or_native_apps\">Adopting the WebP Image Format for Android on Websites Or Native Apps<\/a>\n<\/li>\n<li>\n<a href=\"https:\/\/cloudinary.com\/blog\/top_10_mistakes_in_handling_website_images_and_how_to_solve_them\">10 Website Image Mistakes that Slow Load Times<\/a>\n<\/li>\n<li>\n<a href=\"https:\/\/cloudinary.com\/blog\/adaptive_browser_based_image_format_delivery\">Automatically Reduce Image Size Without Losing Quality<\/a>\n<\/li>\n<li>\n<a href=\"https:\/\/cloudinary.com\/blog\/low_quality_image_placeholders_lqip_explained\">Automate Placeholder Generation and Accelerate Page Loads<\/a>\n<\/li>\n<li>\n<a href=\"https:\/\/cloudinary.com\/blog\/progressive_jpegs_and_green_martians\">3 Ways to Do Progressive JPEG Encoding<\/a>\n<\/li>\n<\/ul>\n<\/div>","protected":false},"excerpt":{"rendered":"","protected":false},"author":41,"featured_media":21896,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_cloudinary_featured_overwrite":false,"footnotes":""},"categories":[1],"tags":[165,227],"class_list":["post-21895","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-image-transformation","tag-performance-optimization"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v25.6 (Yoast SEO v26.9) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Automating the Compression of Image Files with One Line of Code<\/title>\n<meta name=\"description\" content=\"Compress image files automatically with one line of code in React, Vue, PHP, Java, Node, Python, Angular and virtually any type of project you are working on.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/cloudinary.com\/blog\/compression_of_image_files_with_only_one_line_of_code\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Compression of Image Files With Only One Line of Code\" \/>\n<meta property=\"og:description\" content=\"Compress image files automatically with one line of code in React, Vue, PHP, Java, Node, Python, Angular and virtually any type of project you are working on.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cloudinary.com\/blog\/compression_of_image_files_with_only_one_line_of_code\" \/>\n<meta property=\"og:site_name\" content=\"Cloudinary Blog\" \/>\n<meta property=\"article:published_time\" content=\"2019-06-05T15:27:14+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-03-09T20:10:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/v1649721223\/Web_Assets\/blog\/Compress-with-one-line-of-code\/Compress-with-one-line-of-code-jpg?_i=AA\" \/>\n\t<meta property=\"og:image:width\" content=\"1540\" \/>\n\t<meta property=\"og:image:height\" content=\"847\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"NewsArticle\",\"@id\":\"https:\/\/cloudinary.com\/blog\/compression_of_image_files_with_only_one_line_of_code#article\",\"isPartOf\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/compression_of_image_files_with_only_one_line_of_code\"},\"author\":{\"name\":\"\",\"@id\":\"\"},\"headline\":\"Compression of Image Files With Only One Line of Code\",\"datePublished\":\"2019-06-05T15:27:14+00:00\",\"dateModified\":\"2025-03-09T20:10:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/compression_of_image_files_with_only_one_line_of_code\"},\"wordCount\":10,\"publisher\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/compression_of_image_files_with_only_one_line_of_code#primaryimage\"},\"thumbnailUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649721223\/Web_Assets\/blog\/Compress-with-one-line-of-code\/Compress-with-one-line-of-code.jpg?_i=AA\",\"keywords\":[\"Image Transformation\",\"Performance Optimization\"],\"inLanguage\":\"en-US\",\"copyrightYear\":\"2019\",\"copyrightHolder\":{\"@id\":\"https:\/\/cloudinary.com\/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cloudinary.com\/blog\/compression_of_image_files_with_only_one_line_of_code\",\"url\":\"https:\/\/cloudinary.com\/blog\/compression_of_image_files_with_only_one_line_of_code\",\"name\":\"Automating the Compression of Image Files with One Line of Code\",\"isPartOf\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/compression_of_image_files_with_only_one_line_of_code#primaryimage\"},\"image\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/compression_of_image_files_with_only_one_line_of_code#primaryimage\"},\"thumbnailUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649721223\/Web_Assets\/blog\/Compress-with-one-line-of-code\/Compress-with-one-line-of-code.jpg?_i=AA\",\"datePublished\":\"2019-06-05T15:27:14+00:00\",\"dateModified\":\"2025-03-09T20:10:55+00:00\",\"description\":\"Compress image files automatically with one line of code in React, Vue, PHP, Java, Node, Python, Angular and virtually any type of project you are working on.\",\"breadcrumb\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/compression_of_image_files_with_only_one_line_of_code#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cloudinary.com\/blog\/compression_of_image_files_with_only_one_line_of_code\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudinary.com\/blog\/compression_of_image_files_with_only_one_line_of_code#primaryimage\",\"url\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649721223\/Web_Assets\/blog\/Compress-with-one-line-of-code\/Compress-with-one-line-of-code.jpg?_i=AA\",\"contentUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649721223\/Web_Assets\/blog\/Compress-with-one-line-of-code\/Compress-with-one-line-of-code.jpg?_i=AA\",\"width\":1540,\"height\":847},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cloudinary.com\/blog\/compression_of_image_files_with_only_one_line_of_code#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/cloudinary.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Compression of Image Files With Only One Line of Code\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#website\",\"url\":\"https:\/\/cloudinary.com\/blog\/\",\"name\":\"Cloudinary Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/cloudinary.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#organization\",\"name\":\"Cloudinary Blog\",\"url\":\"https:\/\/cloudinary.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA\",\"contentUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA\",\"width\":312,\"height\":60,\"caption\":\"Cloudinary Blog\"},\"image\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Automating the Compression of Image Files with One Line of Code","description":"Compress image files automatically with one line of code in React, Vue, PHP, Java, Node, Python, Angular and virtually any type of project you are working on.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/cloudinary.com\/blog\/compression_of_image_files_with_only_one_line_of_code","og_locale":"en_US","og_type":"article","og_title":"Compression of Image Files With Only One Line of Code","og_description":"Compress image files automatically with one line of code in React, Vue, PHP, Java, Node, Python, Angular and virtually any type of project you are working on.","og_url":"https:\/\/cloudinary.com\/blog\/compression_of_image_files_with_only_one_line_of_code","og_site_name":"Cloudinary Blog","article_published_time":"2019-06-05T15:27:14+00:00","article_modified_time":"2025-03-09T20:10:55+00:00","og_image":[{"width":1540,"height":847,"url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/v1649721223\/Web_Assets\/blog\/Compress-with-one-line-of-code\/Compress-with-one-line-of-code-jpg?_i=AA","type":"image\/jpeg"}],"twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/cloudinary.com\/blog\/compression_of_image_files_with_only_one_line_of_code#article","isPartOf":{"@id":"https:\/\/cloudinary.com\/blog\/compression_of_image_files_with_only_one_line_of_code"},"author":{"name":"","@id":""},"headline":"Compression of Image Files With Only One Line of Code","datePublished":"2019-06-05T15:27:14+00:00","dateModified":"2025-03-09T20:10:55+00:00","mainEntityOfPage":{"@id":"https:\/\/cloudinary.com\/blog\/compression_of_image_files_with_only_one_line_of_code"},"wordCount":10,"publisher":{"@id":"https:\/\/cloudinary.com\/blog\/#organization"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/compression_of_image_files_with_only_one_line_of_code#primaryimage"},"thumbnailUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649721223\/Web_Assets\/blog\/Compress-with-one-line-of-code\/Compress-with-one-line-of-code.jpg?_i=AA","keywords":["Image Transformation","Performance Optimization"],"inLanguage":"en-US","copyrightYear":"2019","copyrightHolder":{"@id":"https:\/\/cloudinary.com\/#organization"}},{"@type":"WebPage","@id":"https:\/\/cloudinary.com\/blog\/compression_of_image_files_with_only_one_line_of_code","url":"https:\/\/cloudinary.com\/blog\/compression_of_image_files_with_only_one_line_of_code","name":"Automating the Compression of Image Files with One Line of Code","isPartOf":{"@id":"https:\/\/cloudinary.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/cloudinary.com\/blog\/compression_of_image_files_with_only_one_line_of_code#primaryimage"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/compression_of_image_files_with_only_one_line_of_code#primaryimage"},"thumbnailUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649721223\/Web_Assets\/blog\/Compress-with-one-line-of-code\/Compress-with-one-line-of-code.jpg?_i=AA","datePublished":"2019-06-05T15:27:14+00:00","dateModified":"2025-03-09T20:10:55+00:00","description":"Compress image files automatically with one line of code in React, Vue, PHP, Java, Node, Python, Angular and virtually any type of project you are working on.","breadcrumb":{"@id":"https:\/\/cloudinary.com\/blog\/compression_of_image_files_with_only_one_line_of_code#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cloudinary.com\/blog\/compression_of_image_files_with_only_one_line_of_code"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudinary.com\/blog\/compression_of_image_files_with_only_one_line_of_code#primaryimage","url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649721223\/Web_Assets\/blog\/Compress-with-one-line-of-code\/Compress-with-one-line-of-code.jpg?_i=AA","contentUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649721223\/Web_Assets\/blog\/Compress-with-one-line-of-code\/Compress-with-one-line-of-code.jpg?_i=AA","width":1540,"height":847},{"@type":"BreadcrumbList","@id":"https:\/\/cloudinary.com\/blog\/compression_of_image_files_with_only_one_line_of_code#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cloudinary.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Compression of Image Files With Only One Line of Code"}]},{"@type":"WebSite","@id":"https:\/\/cloudinary.com\/blog\/#website","url":"https:\/\/cloudinary.com\/blog\/","name":"Cloudinary Blog","description":"","publisher":{"@id":"https:\/\/cloudinary.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/cloudinary.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/cloudinary.com\/blog\/#organization","name":"Cloudinary Blog","url":"https:\/\/cloudinary.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA","contentUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649718331\/Web_Assets\/blog\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877\/cloudinary_logo_for_white_bg_1937437aa7_19374666c7_193742f877.png?_i=AA","width":312,"height":60,"caption":"Cloudinary Blog"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":""}]}},"jetpack_featured_media_url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1649721223\/Web_Assets\/blog\/Compress-with-one-line-of-code\/Compress-with-one-line-of-code.jpg?_i=AA","_links":{"self":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/21895","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/comments?post=21895"}],"version-history":[{"count":7,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/21895\/revisions"}],"predecessor-version":[{"id":37191,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/21895\/revisions\/37191"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/media\/21896"}],"wp:attachment":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/media?parent=21895"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/categories?post=21895"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/tags?post=21895"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}