<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Cecily Toro on Medium]]></title>
        <description><![CDATA[Stories by Cecily Toro on Medium]]></description>
        <link>https://medium.com/@torocecily?source=rss-3c9b97d749a1------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qbPSYPtp3Lw7H2TNK55KXg.png</url>
            <title>Stories by Cecily Toro on Medium</title>
            <link>https://medium.com/@torocecily?source=rss-3c9b97d749a1------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 00:25:53 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@torocecily/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Dynamic Social Media Preview Images Using Cloudinary and NextJS]]></title>
            <link>https://medium.com/@torocecily/dynamic-social-media-preview-images-using-cloudinary-and-nextjs-5c5fea2cb50d?source=rss-3c9b97d749a1------2</link>
            <guid isPermaLink="false">https://medium.com/p/5c5fea2cb50d</guid>
            <category><![CDATA[social-media]]></category>
            <category><![CDATA[unfurl]]></category>
            <category><![CDATA[cloudinary]]></category>
            <category><![CDATA[image]]></category>
            <category><![CDATA[nextjs-tutorial]]></category>
            <dc:creator><![CDATA[Cecily Toro]]></dc:creator>
            <pubDate>Sun, 05 May 2024 22:24:02 GMT</pubDate>
            <atom:updated>2024-05-06T18:45:23.229Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rEM3Vc7ydSyVE4p8r2QRHw.jpeg" /><figcaption>Photo by <a href="https://unsplash.com/@dole777?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">dole777</a> on <a href="https://unsplash.com/photos/black-iphone-4-on-brown-wooden-table-EQSPI11rf68?utm_content=creditCopyText&amp;utm_medium=referral&amp;utm_source=unsplash">Unsplash</a></figcaption></figure><h3>Introduction</h3><p>You’ve spent months of hard work creating your project and it’s finally finished — congratulations! I’m sure you’re eager to share your creation with the world, but first consider what the first impression of your project will be.</p><p>The first glimpse someone will get of your project will oftentimes be from the preview image (AKA “unfurl”) that shows up when you share your project across social media platforms. This seems like a small detail, but can determine whether or not someone clicks on your content or scrolls past.</p><p>In this tutorial, we’re going to explore how to create eye-catching social share preview images using Cloudinary and NextJS. We are also going to take it a few steps further by pulling in dynamic data from each page that will ensure your project makes a lasting — and contextual — first impression.</p><h3>Setting up metadata</h3><p>To be able to update these <a href="https://ogp.me/">Open Graph</a> images, we will need a way to handle our metadata. If you already have this setup within your app, great! If not, NextJS gives us multiple options that make it easy to get this setup. The NextJS docs on this can be found <a href="https://nextjs.org/docs/app/building-your-application/optimizing/metadata">here</a>. Here’s a quick look at how we set ours up.</p><p>We created an ‘seo.jsx’ component which imports and utilizes the built-in <a href="https://nextjs.org/docs/pages/api-reference/components/head">NextJS &lt;Head&gt; component</a>. This component allows you to append elements to the `head` of a page beyond just the preview images.</p><pre>import Head from &#39;next/head&#39;;<br><br>const SEO = ({props}) =&gt; {<br>  const values = {<br>    title: props.title ? `${props.title} | Postman Learning Center`,<br>    description: props.description,<br>    previewImage: &#39;https://voyager.postman.com/social-preview/learning-center/preview-image.jpg&#39;,<br>    url: props.url<br>  };<br><br>  return (<br>    &lt;Head&gt;<br>     // more meta tags <br><br> &lt;title key=&quot;title&quot;&gt;{values.title}&lt;/title&gt;<br> &lt;meta name=&quot;description&quot; content={values.description} /&gt;<br><br> &lt;meta data-react-helmet=&quot;true&quot; property=&quot;twitter:site&quot; content=&quot;@getpostman&quot; /&gt;<br> &lt;meta data-react-helmet=&quot;true&quot; property=&quot;twitter:image&quot; content={values.previewImage} /&gt;<br> &lt;meta data-react-helmet=&quot;true&quot; property=&quot;twitter:domain&quot; content={values.url} /&gt;<br> &lt;meta data-react-helmet=&quot;true&quot; property=&quot;twitter:description&quot; content={values.description} /&gt;<br> &lt;meta data-react-helmet=&quot;true&quot; name=&quot;twitter:title&quot; content={values.title} /&gt;<br> &lt;meta data-react-helmet=&quot;true&quot; name=&quot;twitter:creator&quot; content=&quot;Postman&quot; /&gt;<br> &lt;meta data-react-helmet=&quot;true&quot; name=&quot;twitter:card&quot; content=&quot;summary_large_image&quot; /&gt;<br><br>     // rest of meta tags <br>    &lt;/Head&gt;<br>  ) <br>};<br><br>export default SEO;</pre><p><em>Note: I’ve commented out some of the code within this component to save room and left the meta tags we will be focusing on in this tutorial.</em></p><p>You can see that this component is also taking in some props which we set to a ‘values’ object and use within our meta tags. Those props come from our ‘Post.jsx’ component:</p><pre>import SEO from &#39;@/components/seo&#39;;<br><br>//function to fetch blog posts<br><br>const Post = (props) =&gt; {<br>  const { post } = props;<br><br>  return (<br>    &lt;&gt;<br>     &lt;SEO props={post} /&gt;<br>     //rest of post component<br>    &lt;/&gt;<br>  )<br>};<br><br>export default Post;</pre><p>In this component, we are fetching our `post` and then passing the `post` object as a prop to the SEO component. The `post` object has properties like the `title`, `description`, and `slug` that we will use in our SEO component to help set the metadata and also create our dynamic social preview images.</p><h3>Design your image</h3><p>Now that we have our SEO component setup to create our metadata, let’s start designing! Grab a pencil and paper, or your favorite design software and get a rough sketch of what you want your final image to look like. This doesn’t have to be super detailed, but it will help you to figure out what your starting template should look like.</p><h3>Create your starting template</h3><p>Once you have your basic sketch completed, take a look at it and consider if there are any parts that are <strong>NOT</strong> going to change — things you want in every preview image — those are the elements you will want to include in your template. Anywhere you want to dynamically add in a background color will need to be transparent. Keeping this in mind, create your starting template. It is recommended that the final generated preview image has an aspect ratio of 1.91:1 (or 1200 x 630 pixels).</p><p>This is the starting template I created:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/0*ycWqb1X66ljJRYNw" /><figcaption>Starting template. Left side white background with Postman logo at the top. Right half is transparent.</figcaption></figure><p><em>Note: In the screenshot, I’ve added the checkered portion to show you what areas are transparent — this may not show when you save the file.</em></p><p>If your design includes any additional images, save those along with your starting template and head over to Cloudinary to sign up for an account!</p><h3>Using Cloudinary</h3><p>In Cloudinary, head to the ‘Media Library’ and upload your starting template and any other images you want to use. Once the images are uploaded, make sure the permission is set to ‘Public’. You can also rename the public ID.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/346/0*mnTbAQD8PzmLL_R-" /><figcaption>Screenshot showing a picture in the Cloudinary Media Library.</figcaption></figure><p>When you have everything uploaded, head over to the ‘Transformation Center’ in Cloudinary. In the lower right hand corner, you will see a button where you can add your own image — type in the Public ID of your starting template and click ‘Done’. If you uploaded all of your images within a folder, you will need to type the name of the folder followed by a forward slash and then the Public ID of your image.</p><p>The Transformation Center is your chance to get your starting template looking as close to your initial sketch as possible. Don’t worry about making things dynamic yet, we will do that in NextJS later. For now, just use placeholder images, text, and background colors to get all your elements placed where you want them. Every time you add a transformation, it will get added to the URL above your image.</p><p>When you are happy with your image, click the URL to open it in a new tab. You will want to copy the URL and paste it somewhere you can easily reference and edit later. (I like using the Notes app.) Feel free to edit some of the values in the URL and see how it changes the elements in your image — this will help you get familiar with the parts of the URL and allow you to give meaningful names to your variables later. Here’s what my initial image looked like and the resulting URL (IDs removed to show you where they come from in Cloudinary):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*G3wsI3zCJCCWMa5I" /><figcaption>Postman Learning Center unfurl image.</figcaption></figure><pre>https://res.cloudinary.com/&lt;cloud-name&gt;/image/upload/b_rgb:FFD1BE/&lt;folder-name&gt;:&lt;image-public-id&gt;/c_scale,h_0.75,w_0.75/fl_layer_apply,x_-305,y_30/co_rgb:000000,w_525,c_fit,l_text:Arial_50_normal_left:Learning%20Center%253A%0A%0APostman%20documentation%20overview/fl_layer_apply,x_300/&lt;folder-name&gt;/&lt;template-public-id&gt;</pre><h3>Creating your function</h3><p>Now that we have our completed URL, we can create a function that will generate it and return it for us.</p><p>If you look at the completed URL, you can see that each element of the social image has its own section in the URL where the transformations are applied. Each of these different sections are separated by a forward slash. We will want our function to build each of these sections and then join them together with a forward slash in between.</p><p>Start by adding a `generateSocialImage.js` file to your `lib` folder. We can start by creating the function, and then initializing some variables for the base Cloudinary URL and the cloud name. After you have your variables, add them to the array of `urlParts`. We can also add ‘image’ and ‘upload’ directly to the `urlParts` array since those will not be changing. Make sure you have them in the same order as they appear in your URL, then return the parts joining them with a forward slash.</p><pre>function generateSocialImage() {<br>  const cloudinaryUrlBase = &#39;https://res.cloudinary.com&#39;;<br>  const cloudName = &#39;&lt;your-cloud-name&gt;&#39;;<br><br>  const urlParts = [cloudinaryUrlBase, cloudName, &#39;image&#39;, &#39;upload&#39;]; <br>  return urlParts.join(&#39;/&#39;);<br>}<br><br>export default generateSocialImage;</pre><p>For each section, we will be creating an array to hold all of the transformations in that section. The first transformation section is for the background color. Since in our design we eventually want to have dynamic background colors that go with each topic, this is the perfect time to set up our variables for this. We will start by adding a background color variable and setting it to a default value, then creating the background configuration array. We will also need to add the new `bgConfig` array to the `urlParts` array.</p><pre>function generateSocialImage() {<br>  const cloudinaryUrlBase = &#39;https://res.cloudinary.com&#39;;<br>  const cloudName = &#39;&lt;cloud-name&gt;&#39;;<br>  let bgColor = &#39;FFD1BE&#39;; <br><br>  let bgConfig = [`b_rgb:${bgColor}`];<br><br>  const urlParts = [cloudinaryUrlBase, cloudName, &#39;image&#39;, &#39;upload&#39;, bgConfig]; <br>  return urlParts.join(&#39;/&#39;);<br>}<br><br>export default generateSocialImage;</pre><p>Continue working through each section of the URL in this manner. Assign variables for items that you want to eventually be dynamic, create configuration arrays, then add the configuration array to the final URL array that will be returned. We can also pass in the title as a prop to our function. We will be getting the title from the SEO component, where we will call this function. After going through the rest of the sections of my URL in this way, here is what my function looks like:</p><pre>function generateSocialImage(title) {<br>  const cloudinaryUrlBase = &#39;https://res.cloudinary.com&#39;;<br>  const cloudName = &#39;&lt;your-cloud-name&gt;&#39;;<br>  let bgColor = &#39;FFD1BE&#39;;<br>  let dynamicImg = &#39;homepage&#39;;<br>  const imageScale = &#39;0.75&#39;;<br>  const imageXOffset = &#39;-305&#39;;<br>  const imageYOffset = &#39;30&#39;;<br>  const textColor = &#39;000000&#39;;<br>  const textWidth = &#39;525&#39;;<br>  const font = &#39;Arial&#39;;<br>  const fontSize = &#39;50&#39;;<br>  const fontExtraConfig = &#39;normal_left&#39;;<br>  const textLeftOffset = &#39;300&#39;;<br>  const imagePublicID = &#39;&lt;folder-name&gt;/&lt;template-public-id&gt;&#39;;<br><br>  let bgConfig = [`b_rgb:${bgColor}`];<br>  let image = [`&lt;folder-name&gt;:${dynamicImg}`];<br>  let imageConfig = [&#39;c_scale&#39;, `h_${imageScale}`, `w_${imageScale}`];<br>  let imagePlacement = [&#39;fl_layer_apply&#39;, `x_${imageXOffset}`,     `y_${imageYOffset}`];<br>  let text = [`co_rgb:${textColor}`, `w_${textWidth}`, `c_fit`, `l_text:${font}_${fontSize}_${fontExtraConfig}:Learning%20Center%253A%0A%0A${encodeURIComponent(title)}`];<br>  let textPlacement = [&#39;fl_layer_apply&#39;, `x_${textLeftOffset}`];<br><br><br>  const urlParts = [<br>    cloudinaryUrlBase, <br>    cloudName, <br>    &#39;image&#39;, <br>    &#39;upload&#39;, <br>    bgConfig, <br>    image,<br>    imageConfig,<br>    imagePlacement,<br>    text,<br>    textPlacement,<br>    imagePublicID<br>   ]; <br>  return urlParts.join(&#39;/&#39;);<br>}<br><br>export default generateSocialImage;</pre><p>As you can see from the code above, I’ve stored a lot of the values in variables even though they aren’t something that is going to be dynamically derived. I did this to make it easier to change or update the design in the future. Also, notice how the ‘title’ was passed into `encodeURIComponent()` — this is what gives us the ‘%20’ as spaces in the URL where the title is.</p><p><strong><em>Note: if any of your titles include a comma, you will need to encode them to keep your URL from breaking. By default, encodeURIComponent() encodes commas as ‘%2C’ but Cloudinary requires commas to be encoded as ‘%252C’. To fix this, you can replace all ‘2C’ strings as ‘252C’ in your generated URL.</em></strong></p><p>Now that we have the basic function complete, let’s run our function and make sure it creates the URL properly. Back in your SEO component, import and call your function. I saved the function call in a variable, so I could `console.log` the URL and make sure it builds it correctly.</p><pre>import Head from &#39;next/head&#39;;<br>import generateSocialImage from &#39;@/lib/generateSocialImage&#39;;<br><br>const SEO = ({props}) =&gt; {<br>  let title = props.title;<br>  let socialImageUrl = generateSocialImage(title);<br>  console.log(socialImageUrl);<br><br>  const values = {<br>    title: props.title ? `${props.title} | Postman Learning Center`,<br>    description: props.description,<br>    previewImage: &#39;https://voyager.postman.com/social-preview/learning-center/preview-image.jpg&#39;,<br>    url: props.url<br>  };<br><br>  return (<br>    &lt;Head&gt;<br>     // more meta tags <br><br> &lt;title key=&quot;title&quot;&gt;{values.title}&lt;/title&gt;<br>       &lt;meta name=&quot;description&quot; content={values.description} /&gt;<br><br> &lt;meta data-react-helmet=&quot;true&quot; property=&quot;twitter:site&quot; content=&quot;@getpostman&quot; /&gt;<br>      &lt;meta data-react-helmet=&quot;true&quot; property=&quot;twitter:image&quot; content={values.previewImage} /&gt;<br>      &lt;meta data-react-helmet=&quot;true&quot; property=&quot;twitter:domain&quot; content={values.url} /&gt;<br>      &lt;meta data-react-helmet=&quot;true&quot; property=&quot;twitter:description&quot; content={values.description} /&gt;<br>      &lt;meta data-react-helmet=&quot;true&quot; name=&quot;twitter:title&quot; content={values.title} /&gt;<br>      &lt;meta data-react-helmet=&quot;true&quot; name=&quot;twitter:creator&quot; content=&quot;Postman&quot; /&gt;<br>      &lt;meta data-react-helmet=&quot;true&quot; name=&quot;twitter:card&quot; content=&quot;summary_large_image&quot; /&gt;<br><br>     // rest of meta tags <br>    &lt;/Head&gt;<br>  ) <br>};<br><br>export default SEO;</pre><p>Run your app, navigate to one of your pages, and check that the logged URL—when copy and pasted into a new browser window—displays your image. If you get an error, compare the URL that was created to the URL you saved from the Transformation Center matches exactly.</p><h3>Make content dynamic</h3><p>Now that we have the basic URL built, we can start making things dynamic! Right now we have the `dynamicImg` variable set to always be ‘homepage’. The ‘homepage’ string refers to the Public ID of an image we uploaded to Cloudinary. Instead of having every page use the ‘homepage’ image, let’s use the page slug to assign the image.</p><p>In the SEO component, you are going to want to pass the `generateSocialImage()` function a prop for the page slug.</p><pre>import Head from &#39;next/head&#39;;<br>import generateSocialImage from &#39;@/lib/generateSocialImage&#39;;<br><br>const SEO = ({props}) =&gt; {<br>  let title = props.title<br>  let slugImg = props.slug;<br>  let socialImageUrl = generateSocialImage(title, slugImg);<br>  console.log(socialImageUrl);<br><br>  const values = {<br>    title: props.title ? `${props.title} | Postman Learning Center`,<br>    description: props.description,<br>    previewImage: &#39;https://voyager.postman.com/social-preview/learning-center/preview-image.jpg&#39;,<br>    url: props.url<br>  };<br><br>  return (<br>    &lt;Head&gt;<br>     // more meta tags <br><br> &lt;title key=&quot;title&quot;&gt;{values.title}&lt;/title&gt;<br>       &lt;meta name=&quot;description&quot; content={values.description} /&gt;<br><br> &lt;meta data-react-helmet=&quot;true&quot; property=&quot;twitter:site&quot; content=&quot;@getpostman&quot; /&gt;<br>      &lt;meta data-react-helmet=&quot;true&quot; property=&quot;twitter:image&quot; content={values.previewImage} /&gt;<br>      &lt;meta data-react-helmet=&quot;true&quot; property=&quot;twitter:domain&quot; content={values.url} /&gt;<br>      &lt;meta data-react-helmet=&quot;true&quot; property=&quot;twitter:description&quot; content={values.description} /&gt;<br>      &lt;meta data-react-helmet=&quot;true&quot; name=&quot;twitter:title&quot; content={values.title} /&gt;<br>      &lt;meta data-react-helmet=&quot;true&quot; name=&quot;twitter:creator&quot; content=&quot;Postman&quot; /&gt;<br>      &lt;meta data-react-helmet=&quot;true&quot; name=&quot;twitter:card&quot; content=&quot;summary_large_image&quot; /&gt;<br><br>     // rest of meta tags <br>    &lt;/Head&gt;<br>  ) <br>};<br><br>export default SEO;</pre><p>Then we will need to update our function to accept the prop and use it to make our images dynamic. I will also add an `allSlugs` array to hold the strings of all the possible slug names our pages could have. The strings for these slugs all match <strong><em>exactly</em></strong> to the names of images I saved in my Media Library in Cloudinary. If the names don’t match exactly, then your URL will break. I also added an if statement to see if the `slugImg` string that was passed in as a prop matches any of the strings in the `allSlugs` array. If it does match one of those, then that picture is used in the preview image, but if the `slugImg` doesn’t match any of the provided strings, then it uses the ‘homepage’ image as a fallback.</p><pre>function generateSocialImage(title, slugImg) {<br>  const cloudinaryUrlBase = &#39;https://res.cloudinary.com&#39;;<br>  const cloudName = &#39;&lt;your-cloud-name&gt;&#39;;<br>  let bgColor = &#39;FFD1BE&#39;;<br>  let dynamicImg;<br>  const imageScale = &#39;0.75&#39;;<br>  const imageXOffset = &#39;-305&#39;;<br>  const imageYOffset = &#39;30&#39;;<br>  const textColor = &#39;000000&#39;;<br>  const textWidth = &#39;525&#39;;<br>  const font = &#39;Arial&#39;;<br>  const fontSize = &#39;50&#39;;<br>  const fontExtraConfig = &#39;normal_left&#39;;<br>  const textLeftOffset = &#39;300&#39;;<br>  const imagePublicID = &#39;&lt;folder-name&gt;/&lt;template-public-id&gt;&#39;;<br><br>  let allSlugs = [&#39;homepage&#39;, &#39;integrations&#39;, &#39;developer&#39;];<br><br>  if (allSlugs.includes(slugImg)) {<br>    dynamicImg = slugImg; <br>  } else {<br>    dynamicImg = &#39;homepage&#39;;<br>  }<br><br>  let bgConfig = [`b_rgb:${bgColor}`];<br>  let image = [`&lt;folder-name&gt;:${dynamicImg}`];<br>  let imageConfig = [&#39;c_scale&#39;, `h_${imageScale}`, `w_${imageScale}`];<br>  let imagePlacement = [&#39;fl_layer_apply&#39;, `x_${imageXOffset}`,     `y_${imageYOffset}`];<br>  let text = [`co_rgb:${textColor}`, `w_${textWidth}`, `c_fit`, `l_text:${font}_${fontSize}_${fontExtraConfig}:Learning%20Center%253A%0A%0A${encodeURIComponent(title)}`];<br>  let textPlacement = [&#39;fl_layer_apply&#39;, `x_${textLeftOffset}`];<br><br><br>  const urlParts = [<br>    cloudinaryUrlBase, <br>    cloudName, <br>    &#39;image&#39;, <br>    &#39;upload&#39;, <br>    bgConfig, <br>    image,<br>    imageConfig,<br>    imagePlacement,<br>    text,<br>    textPlacement,<br>    imagePublicID<br>  ]; <br>  return urlParts.join(&#39;/&#39;);<br>}<br><br>export default generateSocialImage;</pre><p>We can do something similar to make the background color dynamic also. I am going to be using two colors, a light orange and a light blue, so I will make an array for each one. Then, I will put the strings of whatever slugs I want to have an orange background into the orange array and do the same for the blue array.</p><pre>function generateSocialImage(title, slugImg) {<br>  const cloudinaryUrlBase = &#39;https://res.cloudinary.com&#39;;<br>  const cloudName = &#39;&lt;your-cloud-name&gt;&#39;;<br>  let bgColor = &#39;FFD1BE&#39;;<br>  let dynamicImg;<br>  const imageScale = &#39;0.75&#39;;<br>  const imageXOffset = &#39;-305&#39;;<br>  const imageYOffset = &#39;30&#39;;<br>  const textColor = &#39;000000&#39;;<br>  const textWidth = &#39;525&#39;;<br>  const font = &#39;Arial&#39;;<br>  const fontSize = &#39;50&#39;;<br>  const fontExtraConfig = &#39;normal_left&#39;;<br>  const textLeftOffset = &#39;300&#39;;<br>  const imagePublicID = &#39;&lt;folder-name&gt;/&lt;template-public-id&gt;&#39;;<br><br>  let allSlugs = [&#39;homepage&#39;, &#39;integrations&#39;, &#39;developer&#39;];<br><br>  if (allSlugs.includes(slugImg)) {<br>    dynamicImg = slugImg; <br>  } else {<br>    dynamicImg = &#39;homepage&#39;;<br>  }<br><br>  let orangeBgImgs = [&#39;homepage&#39;, &#39;integrations&#39;];<br>  let blueBgImgs = [&#39;developer&#39;];<br><br>  let bgConfig = [`b_rgb:${bgColor}`];<br>  let image = [`&lt;folder-name&gt;:${dynamicImg}`];<br>  let imageConfig = [&#39;c_scale&#39;, `h_${imageScale}`, `w_${imageScale}`];<br>  let imagePlacement = [&#39;fl_layer_apply&#39;, `x_${imageXOffset}`,     `y_${imageYOffset}`];<br>  let text = [`co_rgb:${textColor}`, `w_${textWidth}`, `c_fit`, `l_text:${font}_${fontSize}_${fontExtraConfig}:Learning%20Center%253A%0A%0A${encodeURIComponent(title)}`];<br>  let textPlacement = [&#39;fl_layer_apply&#39;, `x_${textLeftOffset}`];<br><br><br>  const urlParts = [<br>    cloudinaryUrlBase, <br>    cloudName, <br>    &#39;image&#39;, <br>    &#39;upload&#39;, <br>    bgConfig, <br>    image,<br>    imageConfig,<br>    imagePlacement,<br>    text,<br>    textPlacement,<br>    imagePublicID<br>  ]; <br>  return urlParts.join(&#39;/&#39;);<br>}<br><br>export default generateSocialImage;</pre><p>Now that we have the color arrays, we need to check which array the `slugImg` is in, and then assign the background color to the desired hex code. <strong><em>Note:</em></strong><em> do not include the ‘#’ before your hex code as it is not included in the Cloudinary URL.</em></p><pre>function generateSocialImage(title, slugImg) {<br>  const cloudinaryUrlBase = &#39;https://res.cloudinary.com&#39;;<br>  const cloudName = &#39;&lt;your-cloud-name&gt;&#39;;<br>  let bgColor = &#39;FFD1BE&#39;;<br>  let dynamicImg;<br>  const imageScale = &#39;0.75&#39;;<br>  const imageXOffset = &#39;-305&#39;;<br>  const imageYOffset = &#39;30&#39;;<br>  const textColor = &#39;000000&#39;;<br>  const textWidth = &#39;525&#39;;<br>  const font = &#39;Arial&#39;;<br>  const fontSize = &#39;50&#39;;<br>  const fontExtraConfig = &#39;normal_left&#39;;<br>  const textLeftOffset = &#39;300&#39;;<br>  const imagePublicID = &#39;&lt;folder-name&gt;/&lt;template-public-id&gt;&#39;;<br><br>  let allSlugs = [&#39;homepage&#39;, &#39;integrations&#39;, &#39;developer&#39;];<br><br>  if (allSlugs.includes(slugImg)) {<br>    dynamicImg = slugImg; <br>  } else {<br>    dynamicImg = &#39;homepage&#39;;<br>  }<br><br>  let orangeBgImgs = [&#39;homepage&#39;, &#39;integrations&#39;];<br>  let blueBgImgs = [&#39;developer&#39;];<br><br>  if (orangeBgImgs.includes(slugImg)) {<br>      bgColor = &#39;FFD1BE&#39;;<br>  }<br><br>  if (blueBgImgs.includes(slugImg)) {<br>      bgColor = &#39;EFF4FE&#39;;<br>    }<br><br>  let bgConfig = [`b_rgb:${bgColor}`];<br>  let image = [`&lt;folder-name&gt;:${dynamicImg}`];<br>  let imageConfig = [&#39;c_scale&#39;, `h_${imageScale}`, `w_${imageScale}`];<br>  let imagePlacement = [&#39;fl_layer_apply&#39;, `x_${imageXOffset}`,     `y_${imageYOffset}`];<br>  let text = [`co_rgb:${textColor}`, `w_${textWidth}`, `c_fit`, `l_text:${font}_${fontSize}_${fontExtraConfig}:Learning%20Center%253A%0A%0A${encodeURIComponent(title)}`];<br>  let textPlacement = [&#39;fl_layer_apply&#39;, `x_${textLeftOffset}`];<br><br><br>  const urlParts = [<br>    cloudinaryUrlBase, <br>    cloudName, <br>    &#39;image&#39;, <br>    &#39;upload&#39;, <br>    bgConfig, <br>    image,<br>    imageConfig,<br>    imagePlacement,<br>    text,<br>    textPlacement,<br>    imagePublicID<br>  ]; <br>  return urlParts.join(&#39;/&#39;);<br>}<br><br>export default generateSocialImage;</pre><p>Our function is now complete! Now all we have to do is go back to our SEO component and set the `og:image` meta tag to our newly created Cloudinary URL. You can do this by going into the ‘values’ object and setting the ‘previewImage’ property to the `socialImageUrl`. After you’ve run your app and tested that the logged URL changes the images and colors correctly, you can also remove your `console.log`.</p><pre>import Head from &#39;next/head&#39;;<br>import generateSocialImage from &#39;@/lib/generateSocialImage&#39;;<br><br>const SEO = ({props}) =&gt; {<br>  let title = props.title<br>  let slugImg = props.slug;<br>  let socialImageUrl = generateSocialImage(title, slugImg);<br><br><br>  const values = {<br>    title: props.title ? `${props.title} | Postman Learning Center`,<br>    description: props.description,<br>    previewImage: socialImageUrl,<br>    url: props.url<br>  };<br><br>  return (<br>    &lt;Head&gt;<br>     // more meta tags <br><br> &lt;title key=&quot;title&quot;&gt;{values.title}&lt;/title&gt;<br>       &lt;meta name=&quot;description&quot; content={values.description} /&gt;<br><br> &lt;meta data-react-helmet=&quot;true&quot; property=&quot;twitter:site&quot; content=&quot;@getpostman&quot; /&gt;<br>      &lt;meta data-react-helmet=&quot;true&quot; property=&quot;twitter:image&quot; content={values.previewImage} /&gt;<br>      &lt;meta data-react-helmet=&quot;true&quot; property=&quot;twitter:domain&quot; content={values.url} /&gt;<br>      &lt;meta data-react-helmet=&quot;true&quot; property=&quot;twitter:description&quot; content={values.description} /&gt;<br>      &lt;meta data-react-helmet=&quot;true&quot; name=&quot;twitter:title&quot; content={values.title} /&gt;<br>      &lt;meta data-react-helmet=&quot;true&quot; name=&quot;twitter:creator&quot; content=&quot;Postman&quot; /&gt;<br>      &lt;meta data-react-helmet=&quot;true&quot; name=&quot;twitter:card&quot; content=&quot;summary_large_image&quot; /&gt;<br><br>     // rest of meta tags <br>    &lt;/Head&gt;<br>  ) <br>};<br><br>export default SEO;</pre><h3>Adding Custom Fonts</h3><p>You now have great-looking, dynamic social preview images, but I’m sure you noticed that the Transformation Center has a very limited selection of fonts. Don’t worry — if you have a custom font you would like to use, we can add that now and take your social preview images to the next level!</p><p>You will need a raw file of the font you want to use. The accepted file types are `.ttf`, `.otf`, or `.woff2`. Unlike images, the font files need to be uploaded using a signed upload request. You can take care of this by logging into your Cloudinary account, and going into your Settings on the lower left hand corner. Once in Settings, click on ‘Upload’ in the sidebar. In the ‘Upload’ menu, scroll down to where it says ‘Upload presets’ and click on ‘Add upload preset’. You can give the preset a name, I named mine the same as the font I was using. Change the ‘Signing Mode’ to ‘Signed’ and then click ‘Save’. Go back to the ‘Upload’ menu and scroll down to the bottom where it says ‘Media Library upload preset defaults’. Set the Raw type to the upload preset you just made. Then click ‘Save’.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*rR6PRyr01RgfYl8Y" /><figcaption>Screenshot of Cloudinary Media Library upload preset defaults.</figcaption></figure><p>Return to the Media Library and upload your font file. Once uploaded, make sure that the Delivery Type and Permission settings say Authenticated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/516/0*HgZMLClMAocYiV3v" /><figcaption>Screenshot of a custom font uploaded to the Cloudinary Media Library</figcaption></figure><p>If you have your font file uploaded correctly, then you can go back to your code editor and go to the `generateSocialImage.js` file. Here you will replace your font variable to the name of the font file you just uploaded, <strong><em>including the file extension</em></strong>.</p><pre>function generateSocialImage(title, slugImg) {<br>  const cloudinaryUrlBase = &#39;https://res.cloudinary.com&#39;;<br>  const cloudName = &#39;&lt;your-cloud-name&gt;&#39;;<br>  let bgColor = &#39;FFD1BE&#39;;<br>  let dynamicImg;<br>  const imageScale = &#39;0.75&#39;;<br>  const imageXOffset = &#39;-305&#39;;<br>  const imageYOffset = &#39;30&#39;;<br>  const textColor = &#39;000000&#39;;<br>  const textWidth = &#39;525&#39;;<br>  const font = &#39;DegularDisplaySemibold.woff2&#39;;<br>  const fontSize = &#39;50&#39;;<br>  const fontExtraConfig = &#39;normal_left&#39;;<br>  const textLeftOffset = &#39;300&#39;;<br>  const imagePublicID = &#39;&lt;folder-name&gt;/&lt;template-public-id&gt;&#39;;<br><br>  let allSlugs = [&#39;homepage&#39;, &#39;integrations&#39;, &#39;developer&#39;];<br><br>  if (allSlugs.includes(slugImg)) {<br>    dynamicImg = slugImg; <br>  } else {<br>    dynamicImg = &#39;homepage&#39;;<br>  }<br><br>  let orangeBgImgs = [&#39;homepage&#39;, &#39;integrations&#39;];<br>  let blueBgImgs = [&#39;developer&#39;];<br><br>  if (orangeBgImgs.includes(slugImg)) {<br>      bgColor = &#39;FFD1BE&#39;;<br>  }<br><br>  if (blueBgImgs.includes(slugImg)) {<br>      bgColor = &#39;EFF4FE&#39;;<br>    }<br><br>  let bgConfig = [`b_rgb:${bgColor}`];<br>  let image = [`&lt;folder-name&gt;:${dynamicImg}`];<br>  let imageConfig = [&#39;c_scale&#39;, `h_${imageScale}`, `w_${imageScale}`];<br>  let imagePlacement = [&#39;fl_layer_apply&#39;, `x_${imageXOffset}`,     `y_${imageYOffset}`];<br>  let text = [`co_rgb:${textColor}`, `w_${textWidth}`, `c_fit`, `l_text:${font}_${fontSize}_${fontExtraConfig}:Learning%20Center%253A%0A%0A${encodeURIComponent(title)}`];<br>  let textPlacement = [&#39;fl_layer_apply&#39;, `x_${textLeftOffset}`];<br><br><br>  const urlParts = [<br>    cloudinaryUrlBase, <br>    cloudName, <br>    &#39;image&#39;, <br>    &#39;upload&#39;, <br>    bgConfig, <br>    image,<br>    imageConfig,<br>    imagePlacement,<br>    text,<br>    textPlacement,<br>    imagePublicID<br>  ]; <br>  return urlParts.join(&#39;/&#39;);<br>}<br><br>export default generateSocialImage;</pre><p>Now if you test your URL, you should see your custom font.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*F3os6YqXfGYGCn57" /><figcaption>Postman Learning Center unfurl image with custom font.</figcaption></figure><h3>Testing</h3><p>While developing your preview images, unfortunately, I have not found a great way to check what your social images will look like. As mentioned previously, I used a `console.log` then copy and pasted the link into a new browser window. You could also check your meta tags in the developer tools and copy the URL from there to paste into another browser window.</p><p>However, once you get your application hosted somewhere, you can simply paste your page URL into a social preview checker and get a preview of what it will look like when shared across social media sites. A couple of the sites I used to test were <a href="https://www.opengraph.xyz/">OpenGraph</a> and <a href="https://socialsharepreview.com/">Social Share Preview</a>.</p><h3>Conclusion</h3><p>I hope this article has helped you to craft dynamic and unique preview images that accurately reflect the essence of your project. Adding these images will help to ensure that your project stands out and gets noticed from the moment they’re shared across social media platforms. Like you, I’m always learning. If you’ve found this blog helpful, or have found a better way to do it, please leave a comment! Also, if you’ve followed this tutorial, I’d love to see what unfurl image designs you came up with — feel free to share and tag me on <a href="https://www.linkedin.com/in/cecilytoro/">LinkedIn</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5c5fea2cb50d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>