{"id":28403,"date":"2022-03-24T19:42:12","date_gmt":"2022-03-24T19:42:12","guid":{"rendered":"http:\/\/Fix-Mismatched-Aspect-Ratio-with-Cloudinary"},"modified":"2022-03-24T19:42:12","modified_gmt":"2022-03-24T19:42:12","slug":"fix-mismatched-aspect-ratio-with-cloudinary","status":"publish","type":"post","link":"https:\/\/cloudinary.com\/blog\/guest_post\/fix-mismatched-aspect-ratio-with-cloudinary\/","title":{"rendered":"Fix Mismatched Aspect Ratio with Cloudinary"},"content":{"rendered":"<div class=\"wp-block-cloudinary-markdown \"><p>When rendering images on the web, aspect ratios are important and can be pretty confusing because there\u2019s no one-size-fits-all. Aspect ratio here refers to the width of an image or screen in relation to its height. Making media display consistently on your site can be a pain because different cameras shoot in various aspect ratios, so the aspect ratios of images vary.<\/p>\n<p>Imagine building an e-commerce site and having a content management system that enables your site user to upload product images. You might want all images occupying the same space on a page without being distorted when someone uploads an image that isn\u2019t the correct size.<\/p>\n<p>What if you\u2019re trying to build a simple gallery that displays images of different animals. You want all your images to conform to a specific width and height, and you want a solution where the ones with different aspect ratios magically fit inside the same area.<\/p>\n<p>In this article, we will build a simple Image Gallery with React that displays a list of images of characters from the TV series, Game of Thrones. We\u2019ll learn three ways we can use Cloudinary to ensure our images maintain the aspect ratio specified.<\/p>\n<p>Here is a link to the demo <a href=\"https:\/\/codesandbox.io\/s\/fix-mismatched-aspect-ratio-with-cloudinary-8oi02\">CodeSandbox<\/a>.<\/p>\n<\/div>\n  \n  <div class=\"wp-block-cloudinary-code-sandbox \">\n    <iframe\n      src=\"https:\/\/codesandbox.io\/embed\/fix-mismatched-aspect-ratio-with-cloudinary-8oi02?theme=dark&amp;codemirror=1&amp;highlights=&amp;editorsize=50&amp;fontsize=14&amp;expanddevtools=0&amp;hidedevtools=0&amp;eslint=0&amp;forcerefresh=0&amp;hidenavigation=0&amp;initialpath=%2F&amp;module=&amp;moduleview=0&amp;previewwindow=&amp;view=&amp;runonclick=1\"\n      height=\"500\"\n      style=\"width: 100%;\"\n      title=\"fix-mismatched-aspect-ratio-with-cloudinary-8oi02\"\n      loading=\"lazy\"\n      allow=\"accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking\"\n      sandbox=\"allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts\"\n    ><\/iframe>\n  <\/div>\n\n  <div class=\"wp-block-cloudinary-markdown \"><h2>Project Setup<\/h2>\n<p>Open your terminal and run the following command to bootstrap a React app in a folder called <code>got-image-gallery<\/code>.<\/p>\n<pre class=\"js-syntax-highlighted\"><span><code class=\"hljs shcb-wrap-lines\">    npx create-react-app got-image-gallery\n    cd got-image-gallery\n<\/code><\/span><\/pre>\n<h2>Cloudinary Setup<\/h2>\n<p>If you don\u2019t have a Cloudinary account, you can <a href=\"https:\/\/cloudinary.com\/signup\">sign up<\/a> for a free account. Log in after creating your account, and on your dashboard page, you should see all your credentials (cloud name, etc.) We are only interested in the cloud name since that\u2019s what we will need in our React application.<\/p>\n<p>In your terminal, run the following command to install the Cloudinary\u2019s React SDK we\u2019ll be using for this project.<\/p>\n<pre class=\"js-syntax-highlighted\"><span><code class=\"hljs shcb-wrap-lines\">    npm install cloudinary-react --save\n<\/code><\/span><\/pre>\n<p>Open your <code>App.js<\/code> file and add the following to it.<\/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\"><span class=\"hljs-keyword\">import<\/span> <span class=\"hljs-string\">\".\/App.css\"<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { useState, useEffect } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">\"react\"<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { Image, Transformation } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">\"cloudinary-react\"<\/span>;\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">App<\/span>(<span class=\"hljs-params\"><\/span>) <\/span>{\n  <span class=\"hljs-keyword\">const<\/span> &#91;characters, setCharacters] = useState(&#91;]);\n  useEffect(<span class=\"hljs-function\"><span class=\"hljs-params\">()<\/span> =&gt;<\/span> {\n    <span class=\"hljs-keyword\">async<\/span> <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">requestCharacters<\/span>(<span class=\"hljs-params\"><\/span>) <\/span>{\n      <span class=\"hljs-keyword\">const<\/span> res = <span class=\"hljs-keyword\">await<\/span> fetch(<span class=\"hljs-string\">\"https:\/\/thronesapi.com\/api\/v2\/Characters\"<\/span>);\n      <span class=\"hljs-keyword\">const<\/span> characters = <span class=\"hljs-keyword\">await<\/span> res.json();\n      setCharacters(characters);\n    }\n    requestCharacters();\n  });\n  <span class=\"hljs-keyword\">return<\/span> (\n    <span class=\"xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">className<\/span>=<span class=\"hljs-string\">\"container\"<\/span>&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">h1<\/span>&gt;<\/span>Game of Thrones<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">h1<\/span>&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">main<\/span> <span class=\"hljs-attr\">className<\/span>=<span class=\"hljs-string\">\"wrapper\"<\/span>&gt;<\/span>\n        {characters.map((character) =&gt; {\n          const { id, imageUrl, fullName, title, family } = character;\n          return (\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">key<\/span>=<span class=\"hljs-string\">{id}<\/span> <span class=\"hljs-attr\">className<\/span>=<span class=\"hljs-string\">\"post\"<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">className<\/span>=<span class=\"hljs-string\">\"imageWrapper\"<\/span>&gt;<\/span>\n                <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Image<\/span> <span class=\"hljs-attr\">cloudName<\/span>=<span class=\"hljs-string\">\"ifeomaimoh\"<\/span> <span class=\"hljs-attr\">publicId<\/span>=<span class=\"hljs-string\">{imageUrl}<\/span> <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"fetch\"<\/span>&gt;<\/span>\n                <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Image<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span> <span class=\"hljs-attr\">className<\/span>=<span class=\"hljs-string\">\"characterDetails\"<\/span>&gt;<\/span>\n                <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">h2<\/span>&gt;<\/span>{fullName}<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">h2<\/span>&gt;<\/span>\n                <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">h4<\/span>&gt;<\/span>{title}<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">h4<\/span>&gt;<\/span>\n                <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">h4<\/span>&gt;<\/span>{family}<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">h4<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n          );\n        })}\n      <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">main<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span><\/span>\n  );\n}\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">default<\/span> App;\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>In the code above, we\u2019re importing <code>useState()<\/code> and <code>useEffect()<\/code> hooks. We\u2019re also importing the <code>Image<\/code> and <code>Transformation<\/code> components from the Cloudinary React library, which will be used to display and add transformations to our images.<\/p>\n<p>We\u2019re using the <code>useEffect()<\/code> hook to fetch our data from this <a href=\"https:\/\/thronesapi.com\/api\/v2\/Characters\">external API endpoint<\/a> and mapping over the <code>characters<\/code> array to display our images using the <code>Image<\/code> component we imported. The Image component accepts our cloud name, copied from our Cloudinary dashboard, the image URL, and fetch.<\/p>\n<p>Run this command to start your development server and head over to <a href=\"http:\/\/localhost:3000\/\">http:\/\/localhost:3000\/<\/a> in your browser.<\/p>\n<p>Here is what your app should look like.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/cloudinary-marketing-res.cloudinary.com\/image\/upload\/c_limit,w_2000\/f_auto\/q_auto\/media_jams\/s_DAE711B742DED49096CF1B9C178B637B44279B713748782FA759823853262F17_1634551708591_CleanShot+2021-10-18+at+14.08.072x.png\" alt=\"\" loading=\"lazy\" class=\"c-transformed-asset\"  width=\"2000\" height=\"1136\"\/><\/p>\n<p>Let\u2019s look at three ways to make our images fit a predefined size using different cropping methods Cloudinary provides.<\/p>\n<h2>Solution 1: Pad Crop Mode<\/h2>\n<p>We can use Cloudinary\u2019s pad crop mode <code>crop = &quot;pad&quot; <\/code> to resize our images to fill the required width and height we specified. This will retain the aspect ratio of the images, but padding will be applied if the aspect ratio of the images doesn\u2019t match the width and height we specified.<\/p>\n<p>Add this Transformation component to your image component.<\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml shcb-wrap-lines\">    return (\n      ...\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Image<\/span>\n          <span class=\"hljs-attr\">cloudName<\/span>=<span class=\"hljs-string\">\"ifeomaimoh\"<\/span>\n          <span class=\"hljs-attr\">publicId<\/span>=<span class=\"hljs-string\">{imageUrl}<\/span>\n          <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"fetch\"<\/span>\n        &gt;<\/span>\n          <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Transformation<\/span> <span class=\"hljs-attr\">background<\/span>=<span class=\"hljs-string\">\"auto\"<\/span> <span class=\"hljs-attr\">height<\/span>=<span class=\"hljs-string\">\"300\"<\/span> <span class=\"hljs-attr\">width<\/span>=<span class=\"hljs-string\">\"300\"<\/span> <span class=\"hljs-attr\">crop<\/span>=<span class=\"hljs-string\">\"pad\"<\/span> \/&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Image<\/span>&gt;<\/span>\n       ...\n    );\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><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>In the code above, we are combining the pad cropping option with the background parameter. Our images will be resized to fill the specified width and height while maintaining their original aspect ratios. If an image doesn\u2019t fit in the specified width and height, padding is applied to fill the required dimensions.<\/p>\n<p>By setting the background parameter to <code>auto<\/code>, we specify that we want to match the background for each image to its content, and Cloudinary would handle this automatically. See here for more on <a href=\"https:\/\/cloudinary.com\/documentation\/transformation_reference#c_pad\">pad crop mode<\/a>.<\/p>\n<p>Head over to your browser to see what the images look like after cropping and padding.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/cloudinary-marketing-res.cloudinary.com\/image\/upload\/c_limit,w_2000\/f_auto\/q_auto\/media_jams\/s_DAE711B742DED49096CF1B9C178B637B44279B713748782FA759823853262F17_1634530996156_CleanShot+2021-10-18+at+08.22.522x.png\" alt=\"\" loading=\"lazy\" class=\"c-transformed-asset\"  width=\"2000\" height=\"1131\"\/><\/p>\n<p>To add padding in a specific or uniform color, just set the <a href=\"https:\/\/cloudinary.com\/documentation\/effects_and_artistic_enhancements#setting_background_color\">background<\/a> parameter to the color you want. There are also options to blur or match the image\u2019s background to its content.<\/p>\n<h2>Solution 2: Fill Crop Mode<\/h2>\n<p>We can use the fill crop mode <code>crop&quot;= &quot;fill&quot; <\/code> to resize our images to fill the exact width and height specified while retaining their original aspect ratios.<\/p>\n<p>Replace the previous Transformation component in your image component with this.<\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml shcb-wrap-lines\">    return (\n      ...\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Image<\/span>\n          <span class=\"hljs-attr\">cloudName<\/span>=<span class=\"hljs-string\">\"ifeomaimoh\"<\/span>\n          <span class=\"hljs-attr\">publicId<\/span>=<span class=\"hljs-string\">{imageUrl}<\/span>\n          <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"fetch\"<\/span>\n        &gt;<\/span>\n          <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Transformation<\/span> <span class=\"hljs-attr\">height<\/span>=<span class=\"hljs-string\">\"300\"<\/span> <span class=\"hljs-attr\">width<\/span>=<span class=\"hljs-string\">\"300\"<\/span> <span class=\"hljs-attr\">crop<\/span>=<span class=\"hljs-string\">\"fill\"<\/span> <span class=\"hljs-attr\">gravity<\/span>=<span class=\"hljs-string\">\"face\"<\/span> \/&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Image<\/span>&gt;<\/span>\n       ...\n    );\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><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>We are using the fill cropping option with the <a href=\"https:\/\/cloudinary.com\/documentation\/gravity_transformations_tutorial\">gravity<\/a> parameter. This cropping mode will generate images resized to the exact dimensions we specified, so all the images on our site will have the same aspect ratio. Images whose dimensions exceed our specified aspect ratio will be cropped to fill the dimensions we specified. As seen in the code above, we use the gravity parameter <code>g_face<\/code>, a built-in face detection feature, to specify that we want the detected face to be the center of the cropped image.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/cloudinary-marketing-res.cloudinary.com\/image\/upload\/c_limit,w_2000\/f_auto\/q_auto\/media_jams\/s_DAE711B742DED49096CF1B9C178B637B44279B713748782FA759823853262F17_1634536967244_CleanShot+2021-10-18+at+10.02.172x.png\" alt=\"\" loading=\"lazy\" class=\"c-transformed-asset\"  width=\"2000\" height=\"1133\"\/><\/p>\n<p>You can also check out the documentation on <code>[fill_pad](https:\/\/cloudinary.com\/documentation\/resizing_and_cropping#fill_pad)<\/code> crop mode, which combines the beauty of the <code>fill<\/code> and <code>pad<\/code> crop modes to avoid cropping out important areas of an image and apply just enough padding when necessary.<\/p>\n<h2>Solution 3: Conditional Cropping<\/h2>\n<p>Cloudinary also supports conditional transformations, one of which is conditional cropping. Conditional cropping can be used by writing conditional expressions that transform our images depending on their aspect ratios if the given condition is met. If an image is in landscape format, we can say that we want it cropped differently than in portrait format.<\/p>\n<p>Replace the previous Transformation component in your Image component with these.<\/p>\n<pre class=\"js-syntax-highlighted\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"HTML, XML\" data-shcb-language-slug=\"xml\"><span><code class=\"hljs language-xml shcb-wrap-lines\">    return (\n      ...\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Image<\/span>\n          <span class=\"hljs-attr\">cloudName<\/span>=<span class=\"hljs-string\">\"ifeomaimoh\"<\/span>\n          <span class=\"hljs-attr\">publicId<\/span>=<span class=\"hljs-string\">{imageUrl}<\/span>\n          <span class=\"hljs-attr\">type<\/span>=<span class=\"hljs-string\">\"fetch\"<\/span>\n        &gt;<\/span>\n          <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Transformation<\/span> <span class=\"hljs-attr\">if<\/span>=<span class=\"hljs-string\">\"ar_gt_1:1\"<\/span> \/&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Transformation<\/span> <span class=\"hljs-attr\">width<\/span>=<span class=\"hljs-string\">\"300\"<\/span> <span class=\"hljs-attr\">height<\/span>=<span class=\"hljs-string\">\"300\"<\/span> <span class=\"hljs-attr\">crop<\/span>=<span class=\"hljs-string\">\"fill\"<\/span> \/&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Transformation<\/span> <span class=\"hljs-attr\">if<\/span>=<span class=\"hljs-string\">\"else\"<\/span> <span class=\"hljs-attr\">width<\/span>=<span class=\"hljs-string\">\"200\"<\/span> <span class=\"hljs-attr\">height<\/span>=<span class=\"hljs-string\">\"300\"<\/span> <span class=\"hljs-attr\">crop<\/span>=<span class=\"hljs-string\">\"fill\"<\/span> \/&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Transformation<\/span> <span class=\"hljs-attr\">if<\/span>=<span class=\"hljs-string\">\"end\"<\/span> \/&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Transformation<\/span> <span class=\"hljs-attr\">radius<\/span>=<span class=\"hljs-string\">\"10\"<\/span> \/&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Image<\/span>&gt;<\/span>\n       ...\n    );\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><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>The <code>if<\/code> parameter is used in the transformation above to specify an initial condition to be met. Using the <code>if_else<\/code> parameter, we provide a fallback transformation that will be applied if the initial condition is not met.<\/p>\n<p>We\u2019re checking to see if the aspect ratio of an image is greater than 1:1 (landscape). If so, we\u2019d want the image to have a width of 300 pixels and a height of 300. However, if the aspect ratio is less than 1:1 (portrait), we want the image to have a width of 200px and a height of 300px.<\/p>\n<p>Here\u2019s what our result looks like.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/cloudinary-marketing-res.cloudinary.com\/image\/upload\/c_limit,w_2000\/f_auto\/q_auto\/media_jams\/s_DAE711B742DED49096CF1B9C178B637B44279B713748782FA759823853262F17_1634546856455_CleanShot+2021-10-18+at+12.47.192x.png\" alt=\"\" loading=\"lazy\" class=\"c-transformed-asset\"  width=\"2000\" height=\"1191\"\/><\/p>\n<p>For more details, see the documentation on <a href=\"https:\/\/cloudinary.com\/documentation\/conditional_transformations\">conditional image transformation<\/a>.<\/p>\n<p>Find the source code here on <a href=\"https:\/\/github.com\/ifeoma-imoh\/fix-mismatched-aspect-ratio-with-cloudinary\">Github<\/a>.<\/p>\n<h2>Conclusion<\/h2>\n<p>This tutorial has showcased a few ways Cloudinary enables us to resize and crop images to ensure they take up the specified width and height allocated using different smart cropping techniques and simply changing a few lines of code.<\/p>\n<p><strong>Additional resources that can be helpful:<\/strong><\/p>\n<ul>\n<li>\n<a href=\"https:\/\/cloudinary.com\/documentation\/react_integration\">Cloudinary\u2019s React SDK v1<\/a>\n<\/li>\n<li>\n<a href=\"https:\/\/cloudinary.com\/documentation\/resizing_and_cropping\">Documentation on Image Resizing and Cropping<\/a>\n<\/li>\n<li>\n<a href=\"https:\/\/cloudinary.com\/documentation\/conditional_transformations\">Documentation on Conditional Transformations<\/a>\n<\/li>\n<\/ul>\n<\/div>","protected":false},"excerpt":{"rendered":"","protected":false},"author":41,"featured_media":28404,"comment_status":"","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_cloudinary_featured_overwrite":false,"footnotes":""},"categories":[1],"tags":[134,370,246,371],"class_list":["post-28403","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-guest-post","tag-image","tag-react","tag-under-review"],"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>Fix Mismatched Aspect Ratio with Cloudinary<\/title>\n<meta name=\"description\" content=\"This article will show how we can resize and crop images to the specified dimensions using different scaling and cropping methods Cloudinary provides.\" \/>\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\/guest_post\/fix-mismatched-aspect-ratio-with-cloudinary\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Fix Mismatched Aspect Ratio with Cloudinary\" \/>\n<meta property=\"og:description\" content=\"This article will show how we can resize and crop images to the specified dimensions using different scaling and cropping methods Cloudinary provides.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cloudinary.com\/blog\/guest_post\/fix-mismatched-aspect-ratio-with-cloudinary\/\" \/>\n<meta property=\"og:site_name\" content=\"Cloudinary Blog\" \/>\n<meta property=\"article:published_time\" content=\"2022-03-24T19:42:12+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681924606\/Web_Assets\/blog\/f83868174ec16dec2c9c8c2ea4953b217a816005-1280x720-1_28404d74e2\/f83868174ec16dec2c9c8c2ea4953b217a816005-1280x720-1_28404d74e2.png?_i=AA\" \/>\n\t<meta property=\"og:image:width\" content=\"1280\" \/>\n\t<meta property=\"og:image:height\" content=\"720\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\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\/guest_post\/fix-mismatched-aspect-ratio-with-cloudinary\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/fix-mismatched-aspect-ratio-with-cloudinary\/\"},\"author\":{\"name\":\"\",\"@id\":\"\"},\"headline\":\"Fix Mismatched Aspect Ratio with Cloudinary\",\"datePublished\":\"2022-03-24T19:42:12+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/fix-mismatched-aspect-ratio-with-cloudinary\/\"},\"wordCount\":6,\"publisher\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/fix-mismatched-aspect-ratio-with-cloudinary\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681924606\/Web_Assets\/blog\/f83868174ec16dec2c9c8c2ea4953b217a816005-1280x720-1_28404d74e2\/f83868174ec16dec2c9c8c2ea4953b217a816005-1280x720-1_28404d74e2.png?_i=AA\",\"keywords\":[\"Guest Post\",\"Image\",\"React\",\"Under Review\"],\"inLanguage\":\"en-US\",\"copyrightYear\":\"2022\",\"copyrightHolder\":{\"@id\":\"https:\/\/cloudinary.com\/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/fix-mismatched-aspect-ratio-with-cloudinary\/\",\"url\":\"https:\/\/cloudinary.com\/blog\/guest_post\/fix-mismatched-aspect-ratio-with-cloudinary\/\",\"name\":\"Fix Mismatched Aspect Ratio with Cloudinary\",\"isPartOf\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/fix-mismatched-aspect-ratio-with-cloudinary\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/fix-mismatched-aspect-ratio-with-cloudinary\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681924606\/Web_Assets\/blog\/f83868174ec16dec2c9c8c2ea4953b217a816005-1280x720-1_28404d74e2\/f83868174ec16dec2c9c8c2ea4953b217a816005-1280x720-1_28404d74e2.png?_i=AA\",\"datePublished\":\"2022-03-24T19:42:12+00:00\",\"description\":\"This article will show how we can resize and crop images to the specified dimensions using different scaling and cropping methods Cloudinary provides.\",\"breadcrumb\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/fix-mismatched-aspect-ratio-with-cloudinary\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cloudinary.com\/blog\/guest_post\/fix-mismatched-aspect-ratio-with-cloudinary\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/fix-mismatched-aspect-ratio-with-cloudinary\/#primaryimage\",\"url\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681924606\/Web_Assets\/blog\/f83868174ec16dec2c9c8c2ea4953b217a816005-1280x720-1_28404d74e2\/f83868174ec16dec2c9c8c2ea4953b217a816005-1280x720-1_28404d74e2.png?_i=AA\",\"contentUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681924606\/Web_Assets\/blog\/f83868174ec16dec2c9c8c2ea4953b217a816005-1280x720-1_28404d74e2\/f83868174ec16dec2c9c8c2ea4953b217a816005-1280x720-1_28404d74e2.png?_i=AA\",\"width\":1280,\"height\":720},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/fix-mismatched-aspect-ratio-with-cloudinary\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/cloudinary.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Fix Mismatched Aspect Ratio with Cloudinary\"}]},{\"@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":"Fix Mismatched Aspect Ratio with Cloudinary","description":"This article will show how we can resize and crop images to the specified dimensions using different scaling and cropping methods Cloudinary provides.","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\/guest_post\/fix-mismatched-aspect-ratio-with-cloudinary\/","og_locale":"en_US","og_type":"article","og_title":"Fix Mismatched Aspect Ratio with Cloudinary","og_description":"This article will show how we can resize and crop images to the specified dimensions using different scaling and cropping methods Cloudinary provides.","og_url":"https:\/\/cloudinary.com\/blog\/guest_post\/fix-mismatched-aspect-ratio-with-cloudinary\/","og_site_name":"Cloudinary Blog","article_published_time":"2022-03-24T19:42:12+00:00","og_image":[{"width":1280,"height":720,"url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681924606\/Web_Assets\/blog\/f83868174ec16dec2c9c8c2ea4953b217a816005-1280x720-1_28404d74e2\/f83868174ec16dec2c9c8c2ea4953b217a816005-1280x720-1_28404d74e2.png?_i=AA","type":"image\/png"}],"twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/cloudinary.com\/blog\/guest_post\/fix-mismatched-aspect-ratio-with-cloudinary\/#article","isPartOf":{"@id":"https:\/\/cloudinary.com\/blog\/guest_post\/fix-mismatched-aspect-ratio-with-cloudinary\/"},"author":{"name":"","@id":""},"headline":"Fix Mismatched Aspect Ratio with Cloudinary","datePublished":"2022-03-24T19:42:12+00:00","mainEntityOfPage":{"@id":"https:\/\/cloudinary.com\/blog\/guest_post\/fix-mismatched-aspect-ratio-with-cloudinary\/"},"wordCount":6,"publisher":{"@id":"https:\/\/cloudinary.com\/blog\/#organization"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/guest_post\/fix-mismatched-aspect-ratio-with-cloudinary\/#primaryimage"},"thumbnailUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681924606\/Web_Assets\/blog\/f83868174ec16dec2c9c8c2ea4953b217a816005-1280x720-1_28404d74e2\/f83868174ec16dec2c9c8c2ea4953b217a816005-1280x720-1_28404d74e2.png?_i=AA","keywords":["Guest Post","Image","React","Under Review"],"inLanguage":"en-US","copyrightYear":"2022","copyrightHolder":{"@id":"https:\/\/cloudinary.com\/#organization"}},{"@type":"WebPage","@id":"https:\/\/cloudinary.com\/blog\/guest_post\/fix-mismatched-aspect-ratio-with-cloudinary\/","url":"https:\/\/cloudinary.com\/blog\/guest_post\/fix-mismatched-aspect-ratio-with-cloudinary\/","name":"Fix Mismatched Aspect Ratio with Cloudinary","isPartOf":{"@id":"https:\/\/cloudinary.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/cloudinary.com\/blog\/guest_post\/fix-mismatched-aspect-ratio-with-cloudinary\/#primaryimage"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/guest_post\/fix-mismatched-aspect-ratio-with-cloudinary\/#primaryimage"},"thumbnailUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681924606\/Web_Assets\/blog\/f83868174ec16dec2c9c8c2ea4953b217a816005-1280x720-1_28404d74e2\/f83868174ec16dec2c9c8c2ea4953b217a816005-1280x720-1_28404d74e2.png?_i=AA","datePublished":"2022-03-24T19:42:12+00:00","description":"This article will show how we can resize and crop images to the specified dimensions using different scaling and cropping methods Cloudinary provides.","breadcrumb":{"@id":"https:\/\/cloudinary.com\/blog\/guest_post\/fix-mismatched-aspect-ratio-with-cloudinary\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cloudinary.com\/blog\/guest_post\/fix-mismatched-aspect-ratio-with-cloudinary\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudinary.com\/blog\/guest_post\/fix-mismatched-aspect-ratio-with-cloudinary\/#primaryimage","url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681924606\/Web_Assets\/blog\/f83868174ec16dec2c9c8c2ea4953b217a816005-1280x720-1_28404d74e2\/f83868174ec16dec2c9c8c2ea4953b217a816005-1280x720-1_28404d74e2.png?_i=AA","contentUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681924606\/Web_Assets\/blog\/f83868174ec16dec2c9c8c2ea4953b217a816005-1280x720-1_28404d74e2\/f83868174ec16dec2c9c8c2ea4953b217a816005-1280x720-1_28404d74e2.png?_i=AA","width":1280,"height":720},{"@type":"BreadcrumbList","@id":"https:\/\/cloudinary.com\/blog\/guest_post\/fix-mismatched-aspect-ratio-with-cloudinary\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cloudinary.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Fix Mismatched Aspect Ratio with Cloudinary"}]},{"@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\/v1681924606\/Web_Assets\/blog\/f83868174ec16dec2c9c8c2ea4953b217a816005-1280x720-1_28404d74e2\/f83868174ec16dec2c9c8c2ea4953b217a816005-1280x720-1_28404d74e2.png?_i=AA","_links":{"self":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/28403","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=28403"}],"version-history":[{"count":0,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/28403\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/media\/28404"}],"wp:attachment":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/media?parent=28403"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/categories?post=28403"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/tags?post=28403"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}