{"id":28526,"date":"2022-06-28T10:19:51","date_gmt":"2022-06-28T10:19:51","guid":{"rendered":"http:\/\/generate-cartoon-avatars-in-next"},"modified":"2025-02-24T15:14:13","modified_gmt":"2025-02-24T23:14:13","slug":"generate-cartoon-avatars-in-next","status":"publish","type":"post","link":"https:\/\/cloudinary.com\/blog\/guest_post\/generate-cartoon-avatars-in-next\/","title":{"rendered":"Generate Cartoon Avatars in NextJS"},"content":{"rendered":"<div class=\"wp-block-cloudinary-markdown \"><p>Having an avatar as a profile picture is pretty common these days. There are plenty of tools and artists that can create anything you want so you have unlimited options. You can get as particular as you want and maybe even come up with something no one has seen before.<\/p>\n<p>Of course, there\u2019s a way to generate all kinds of avatars with JavaScript. That\u2019s what we\u2019ll be doing in this post with <a href=\"https:\/\/github.com\/dumbmatter\/facesjs\"><code>faces.js<\/code><\/a>. This library lets us generate avatars based on a number of factors so we can have a little fun with this.<\/p>\n<h2>Initial setup<\/h2>\n<p>We\u2019ll this cartoon avatar generator with Next. The whole app will be a form with a number of dropdowns the user can change to get different features for their avatar and then it\u2019ll immediately update the displayed avatar. Let\u2019s start by creating a new Next app with the following command:<\/p>\n<pre class=\"js-syntax-highlighted\"><span><code class=\"hljs shcb-wrap-lines\">$ yarn create next-app --typescript\n<\/code><\/span><\/pre>\n<p>Follow the prompts and name the project <code>cartoon-avatar<\/code>. Then we need to install the <a href=\"https:\/\/www.npmjs.com\/package\/facesjs\"><code>faces.js<\/code><\/a> package. We\u2019ll also be using the <a href=\"https:\/\/mui.com\/\">Material UI library<\/a> to make the app look better from the beginning. So run the following command to install everything we need:<\/p>\n<pre class=\"js-syntax-highlighted\"><span><code class=\"hljs shcb-wrap-lines\">$ yarn add facesjs @mui\/material @emotion\/react @emotion\/styled\n<\/code><\/span><\/pre>\n<p>This is all we need to make this app work and look good. Now we can turn our attention to the code. We\u2019ll start by building the form since it will have the most moving pieces and it should be its own component.<\/p>\n<h2>Create the form<\/h2>\n<p>First, let\u2019s create a new folder inside the <code>pages<\/code> folder called <code>components<\/code>. Inside this new components folder, make a new file called <code>Form.tsx<\/code>. This will have a lot of code in it, but remember that it\u2019s only because we have a lot of options that we want to offer the user to customize their avatars. So in the <code>Form.tsx<\/code> file, add the following code:<\/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-comment\">\/\/ Form.tsx<\/span>\n<span class=\"hljs-keyword\">import<\/span> {\n  Container,\n  FormControl,\n  InputLabel,\n  MenuItem,\n  Select,\n  Stack,\n} <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">\"@mui\/material\"<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { Options } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">\"..\/index\"<\/span>;\n\ninterface FormProps {\n  <span class=\"hljs-attr\">options<\/span>: Options;\n  updateAvatar: <span class=\"hljs-function\">(<span class=\"hljs-params\">options: any<\/span>) =&gt;<\/span> <span class=\"hljs-keyword\">void<\/span>;\n}\n\n<span class=\"hljs-keyword\">const<\/span> Form = <span class=\"hljs-function\">(<span class=\"hljs-params\">{ options, updateAvatar }: FormProps<\/span>) =&gt;<\/span> {\n  <span class=\"hljs-keyword\">return<\/span> (\n    <span class=\"xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Container<\/span>&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">form<\/span>\n        <span class=\"hljs-attr\">style<\/span>=<span class=\"hljs-string\">{{<\/span>\n          <span class=\"hljs-attr\">marginBottom:<\/span> \"<span class=\"hljs-attr\">24px<\/span>\",\n          <span class=\"hljs-attr\">marginTop:<\/span> \"<span class=\"hljs-attr\">24px<\/span>\",\n          <span class=\"hljs-attr\">width:<\/span> \"<span class=\"hljs-attr\">800px<\/span>\",\n        }}\n      &gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Stack<\/span> <span class=\"hljs-attr\">spacing<\/span>=<span class=\"hljs-string\">{2}<\/span>&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">FormControl<\/span> <span class=\"hljs-attr\">variant<\/span>=<span class=\"hljs-string\">\"standard\"<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">InputLabel<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"body\"<\/span>&gt;<\/span>Body<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">InputLabel<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Select<\/span>\n              <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"body\"<\/span>\n              <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"body\"<\/span>\n              <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">{options.body.id}<\/span>\n              <span class=\"hljs-attr\">onChange<\/span>=<span class=\"hljs-string\">{(e)<\/span> =&gt;<\/span> updateAvatar(e)}\n              label=\"Body\"\n            &gt;\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">MenuItem<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"body\"<\/span>&gt;<\/span>\n                <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">em<\/span>&gt;<\/span>None<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">em<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">MenuItem<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">MenuItem<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"body2\"<\/span>&gt;<\/span>Type 1<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">MenuItem<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">MenuItem<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"body3\"<\/span>&gt;<\/span>Type 2<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">MenuItem<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">MenuItem<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"body5\"<\/span>&gt;<\/span>Type 3<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">MenuItem<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Select<\/span>&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">FormControl<\/span>&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">FormControl<\/span> <span class=\"hljs-attr\">variant<\/span>=<span class=\"hljs-string\">\"standard\"<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">InputLabel<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"ear\"<\/span>&gt;<\/span>Ear<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">InputLabel<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Select<\/span>\n              <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"ear\"<\/span>\n              <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"ear\"<\/span>\n              <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">{options.ear.id}<\/span>\n              <span class=\"hljs-attr\">onChange<\/span>=<span class=\"hljs-string\">{(e)<\/span> =&gt;<\/span> updateAvatar(e)}\n              label=\"Ear\"\n            &gt;\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">MenuItem<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"ear1\"<\/span>&gt;<\/span>\n                <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">em<\/span>&gt;<\/span>None<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">em<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">MenuItem<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">MenuItem<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"ear2\"<\/span>&gt;<\/span>Type 1<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">MenuItem<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">MenuItem<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"ear3\"<\/span>&gt;<\/span>Type 2<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">MenuItem<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Select<\/span>&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">FormControl<\/span>&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">FormControl<\/span> <span class=\"hljs-attr\">variant<\/span>=<span class=\"hljs-string\">\"standard\"<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">InputLabel<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"eye\"<\/span>&gt;<\/span>Eye<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">InputLabel<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Select<\/span>\n              <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"eye\"<\/span>\n              <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"eye\"<\/span>\n              <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">{options.eye.id}<\/span>\n              <span class=\"hljs-attr\">onChange<\/span>=<span class=\"hljs-string\">{(e)<\/span> =&gt;<\/span> updateAvatar(e)}\n              label=\"Eye\"\n            &gt;\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">MenuItem<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"eye13\"<\/span>&gt;<\/span>\n                <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">em<\/span>&gt;<\/span>None<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">em<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">MenuItem<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">MenuItem<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"eye5\"<\/span>&gt;<\/span>Type 1<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">MenuItem<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">MenuItem<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"eye19\"<\/span>&gt;<\/span>Type 2<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">MenuItem<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">MenuItem<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"eye12\"<\/span>&gt;<\/span>Type 3<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">MenuItem<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Select<\/span>&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">FormControl<\/span>&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">FormControl<\/span> <span class=\"hljs-attr\">variant<\/span>=<span class=\"hljs-string\">\"standard\"<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">InputLabel<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"facialHair\"<\/span>&gt;<\/span>Facial Hair<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">InputLabel<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Select<\/span>\n              <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"facialHair\"<\/span>\n              <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"facialHair\"<\/span>\n              <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">{options.facialHair.id}<\/span>\n              <span class=\"hljs-attr\">onChange<\/span>=<span class=\"hljs-string\">{(e)<\/span> =&gt;<\/span> updateAvatar(e)}\n              label=\"Facial Hair\"\n            &gt;\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">MenuItem<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"none\"<\/span>&gt;<\/span>\n                <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">em<\/span>&gt;<\/span>None<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">em<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">MenuItem<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">MenuItem<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"fullgoatee4\"<\/span>&gt;<\/span>Type 1<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">MenuItem<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">MenuItem<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"loganSoul\"<\/span>&gt;<\/span>Type 2<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">MenuItem<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">MenuItem<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"sideburns3\"<\/span>&gt;<\/span>Type 3<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">MenuItem<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Select<\/span>&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">FormControl<\/span>&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">FormControl<\/span> <span class=\"hljs-attr\">variant<\/span>=<span class=\"hljs-string\">\"standard\"<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">InputLabel<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"glasses\"<\/span>&gt;<\/span>Glasses<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">InputLabel<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Select<\/span>\n              <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"glasses\"<\/span>\n              <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"glasses\"<\/span>\n              <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">{options.glasses.id}<\/span>\n              <span class=\"hljs-attr\">onChange<\/span>=<span class=\"hljs-string\">{(e)<\/span> =&gt;<\/span> updateAvatar(e)}\n              label=\"Glasses\"\n            &gt;\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">MenuItem<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"none\"<\/span>&gt;<\/span>\n                <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">em<\/span>&gt;<\/span>None<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">em<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">MenuItem<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">MenuItem<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"glasses1-primary\"<\/span>&gt;<\/span>Type 1<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">MenuItem<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">MenuItem<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"glasses2-primary\"<\/span>&gt;<\/span>Type 2<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">MenuItem<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">MenuItem<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"glasses2-black\"<\/span>&gt;<\/span>Type 3<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">MenuItem<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Select<\/span>&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">FormControl<\/span>&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">FormControl<\/span> <span class=\"hljs-attr\">variant<\/span>=<span class=\"hljs-string\">\"standard\"<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">InputLabel<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"hair\"<\/span>&gt;<\/span>Hair<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">InputLabel<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Select<\/span>\n              <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"hair\"<\/span>\n              <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"hair\"<\/span>\n              <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">{options.hair.id}<\/span>\n              <span class=\"hljs-attr\">onChange<\/span>=<span class=\"hljs-string\">{(e)<\/span> =&gt;<\/span> updateAvatar(e)}\n              label=\"Hair\"\n            &gt;\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">MenuItem<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"blowoutFade\"<\/span>&gt;<\/span>\n                <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">em<\/span>&gt;<\/span>None<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">em<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">MenuItem<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">MenuItem<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"curly\"<\/span>&gt;<\/span>Type 1<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">MenuItem<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">MenuItem<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"juice\"<\/span>&gt;<\/span>Type 2<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">MenuItem<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">MenuItem<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"parted\"<\/span>&gt;<\/span>Type 3<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">MenuItem<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Select<\/span>&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">FormControl<\/span>&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">FormControl<\/span> <span class=\"hljs-attr\">variant<\/span>=<span class=\"hljs-string\">\"standard\"<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">InputLabel<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"head\"<\/span>&gt;<\/span>Head<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">InputLabel<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Select<\/span>\n              <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"head\"<\/span>\n              <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"head\"<\/span>\n              <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">{options.head.id}<\/span>\n              <span class=\"hljs-attr\">onChange<\/span>=<span class=\"hljs-string\">{(e)<\/span> =&gt;<\/span> updateAvatar(e)}\n              label=\"Head\"\n            &gt;\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">MenuItem<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"head8\"<\/span>&gt;<\/span>\n                <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">em<\/span>&gt;<\/span>None<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">em<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">MenuItem<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">MenuItem<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"head14\"<\/span>&gt;<\/span>Type 1<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">MenuItem<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">MenuItem<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"head3\"<\/span>&gt;<\/span>Type 2<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">MenuItem<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">MenuItem<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"head10\"<\/span>&gt;<\/span>Type 3<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">MenuItem<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Select<\/span>&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">FormControl<\/span>&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">FormControl<\/span> <span class=\"hljs-attr\">variant<\/span>=<span class=\"hljs-string\">\"standard\"<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">InputLabel<\/span> <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"nose\"<\/span>&gt;<\/span>Nose<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">InputLabel<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Select<\/span>\n              <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"nose\"<\/span>\n              <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"nose\"<\/span>\n              <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">{options.nose.id}<\/span>\n              <span class=\"hljs-attr\">onChange<\/span>=<span class=\"hljs-string\">{(e)<\/span> =&gt;<\/span> updateAvatar(e)}\n              label=\"Nose\"\n            &gt;\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">MenuItem<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"nose6\"<\/span>&gt;<\/span>\n                <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">em<\/span>&gt;<\/span>None<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">em<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">MenuItem<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">MenuItem<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"nose5\"<\/span>&gt;<\/span>Type 1<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">MenuItem<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">MenuItem<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"nose13\"<\/span>&gt;<\/span>Type 2<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">MenuItem<\/span>&gt;<\/span>\n              <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">MenuItem<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"nose9\"<\/span>&gt;<\/span>Type 3<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">MenuItem<\/span>&gt;<\/span>\n            <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Select<\/span>&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">FormControl<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Stack<\/span>&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">form<\/span>&gt;<\/span>\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Container<\/span>&gt;<\/span><\/span>\n  );\n};\n\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">default<\/span> Form;\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>The first thing we do is import some components from MUI and a type from the <code>index.tsx<\/code> file. Don\u2019t worry about that type yet because we\u2019ll get to it in a later section. After all the imports, we create another type for the props that get sent to the form. Finally, we write the return statement that has the form fields.<\/p>\n<p>There are 9 option dropdowns with 3-4 variations each. The options and their variants are based on values directly from the <code>faces.js<\/code> library. You can play around with some of the other SVG values provided by the library if you want to add more variants or options. Each time a dropdown is changed, we call the <code>updateAvatar<\/code> function that gets passed as a prop.<\/p>\n<p>This is everything for the form users will interact with. Now we can jump over to the part where we actually render the avatar based on the user\u2019s inputs.<\/p>\n<h2>Add the avatar<\/h2>\n<p>This is where we get to have some fun and see things in action. Open the <code>index.tsx<\/code> file in the <code>pages<\/code> folder and delete everything. Then add the following code:<\/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\"><span class=\"hljs-comment\">\/\/ index.tsx<\/span>\n<span class=\"hljs-keyword\">import<\/span> type { NextPage } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">\"next\"<\/span>;\n<span class=\"hljs-keyword\">import<\/span> Head <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">\"next\/head\"<\/span>;\n<span class=\"hljs-keyword\">import<\/span> * <span class=\"hljs-keyword\">as<\/span> faces <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">\"facesjs\"<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { useEffect, useState } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">\"react\"<\/span>;\n<span class=\"hljs-keyword\">import<\/span> { Container } <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">\"@mui\/material\"<\/span>;\n<span class=\"hljs-keyword\">import<\/span> Form <span class=\"hljs-keyword\">from<\/span> <span class=\"hljs-string\">\".\/components\/Form\"<\/span>;\n\n<span class=\"hljs-keyword\">export<\/span> interface Options {\n  <span class=\"hljs-attr\">body<\/span>: { <span class=\"hljs-attr\">id<\/span>: string };\n  ear: { <span class=\"hljs-attr\">id<\/span>: string };\n  eye: { <span class=\"hljs-attr\">id<\/span>: string };\n  facialHair: { <span class=\"hljs-attr\">id<\/span>: string };\n  glasses: { <span class=\"hljs-attr\">id<\/span>: string };\n  hair: { <span class=\"hljs-attr\">id<\/span>: string };\n  head: { <span class=\"hljs-attr\">id<\/span>: string };\n  mouth: { <span class=\"hljs-attr\">id<\/span>: string };\n  nose: { <span class=\"hljs-attr\">id<\/span>: string };\n}\n\n<span class=\"hljs-keyword\">const<\/span> Home: NextPage = <span class=\"hljs-function\"><span class=\"hljs-params\">()<\/span> =&gt;<\/span> {\n  <span class=\"hljs-keyword\">const<\/span> &#91;options, setOptions] = useState&lt;Options&gt;({\n    <span class=\"hljs-attr\">body<\/span>: { <span class=\"hljs-attr\">id<\/span>: <span class=\"hljs-string\">\"body2\"<\/span> },\n    <span class=\"hljs-attr\">ear<\/span>: { <span class=\"hljs-attr\">id<\/span>: <span class=\"hljs-string\">\"ear3\"<\/span> },\n    <span class=\"hljs-attr\">eye<\/span>: { <span class=\"hljs-attr\">id<\/span>: <span class=\"hljs-string\">\"eye5\"<\/span> },\n    <span class=\"hljs-attr\">facialHair<\/span>: { <span class=\"hljs-attr\">id<\/span>: <span class=\"hljs-string\">\"none\"<\/span> },\n    <span class=\"hljs-attr\">glasses<\/span>: { <span class=\"hljs-attr\">id<\/span>: <span class=\"hljs-string\">\"glasses2-black\"<\/span> },\n    <span class=\"hljs-attr\">hair<\/span>: { <span class=\"hljs-attr\">id<\/span>: <span class=\"hljs-string\">\"juice\"<\/span> },\n    <span class=\"hljs-attr\">head<\/span>: { <span class=\"hljs-attr\">id<\/span>: <span class=\"hljs-string\">\"head3\"<\/span> },\n    <span class=\"hljs-attr\">mouth<\/span>: { <span class=\"hljs-attr\">id<\/span>: <span class=\"hljs-string\">\"mouth5\"<\/span> },\n    <span class=\"hljs-attr\">nose<\/span>: { <span class=\"hljs-attr\">id<\/span>: <span class=\"hljs-string\">\"nose9\"<\/span> },\n  });\n\n  <span class=\"hljs-keyword\">const<\/span> face = faces.generate();\n\n  useEffect(<span class=\"hljs-function\"><span class=\"hljs-params\">()<\/span> =&gt;<\/span> {\n    faces.display(<span class=\"hljs-string\">\"avatar\"<\/span>, face, options);\n  }, &#91;face, options]);\n\n  <span class=\"hljs-function\"><span class=\"hljs-keyword\">function<\/span> <span class=\"hljs-title\">updateAvatar<\/span>(<span class=\"hljs-params\">e: any<\/span>) <\/span>{\n    e.preventDefault();\n\n    <span class=\"hljs-keyword\">const<\/span> updatedOptions = {\n      ...options,\n      &#91;e.target.name]: { <span class=\"hljs-attr\">id<\/span>: e.target.value },\n    };\n\n    setOptions(updatedOptions);\n  }\n\n  <span class=\"hljs-keyword\">return<\/span> (\n    <span class=\"xml\"><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Head<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">title<\/span>&gt;<\/span>What Avatar Is Yours<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">title<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">meta<\/span>\n          <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"description\"<\/span>\n          <span class=\"hljs-attr\">content<\/span>=<span class=\"hljs-string\">\"uses faces.js to make random avatars\"<\/span>\n        \/&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">link<\/span> <span class=\"hljs-attr\">rel<\/span>=<span class=\"hljs-string\">\"icon\"<\/span> <span class=\"hljs-attr\">href<\/span>=<span class=\"hljs-string\">\"\/favicon.ico\"<\/span> \/&gt;<\/span>\n      <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Head<\/span>&gt;<\/span>\n\n      <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">main<\/span> <span class=\"hljs-attr\">style<\/span>=<span class=\"hljs-string\">{{<\/span> <span class=\"hljs-attr\">width:<\/span> \"<span class=\"hljs-attr\">100<\/span>%\" }}&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Container<\/span>&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">h1<\/span>&gt;<\/span>{`What's your face?`}<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">h1<\/span>&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">Form<\/span> <span class=\"hljs-attr\">options<\/span>=<span class=\"hljs-string\">{options}<\/span> <span class=\"hljs-attr\">updateAvatar<\/span>=<span class=\"hljs-string\">{updateAvatar}<\/span> \/&gt;<\/span>\n          <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">div<\/span>\n            <span class=\"hljs-attr\">id<\/span>=<span class=\"hljs-string\">\"avatar\"<\/span>\n            <span class=\"hljs-attr\">style<\/span>=<span class=\"hljs-string\">{{<\/span> <span class=\"hljs-attr\">margin:<\/span> \"<span class=\"hljs-attr\">0<\/span> <span class=\"hljs-attr\">auto<\/span>\", <span class=\"hljs-attr\">height:<\/span> \"<span class=\"hljs-attr\">auto<\/span>\", <span class=\"hljs-attr\">width:<\/span> \"<span class=\"hljs-attr\">300px<\/span>\" }}\n          &gt;<\/span><span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">div<\/span>&gt;<\/span>\n        <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">Container<\/span>&gt;<\/span>\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\n<span class=\"hljs-keyword\">export<\/span> <span class=\"hljs-keyword\">default<\/span> Home;\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>This is where we display the form and the avatar to users. We start by importing a few components and methods we need. You\u2019ll see the <code>faces.js<\/code> library and our custom form component to note a few things. Next, we define the <code>Options<\/code> type that we imported in the <code>Form<\/code> component. So we know what the <code>faces.js<\/code> library expects. Then we get into the <code>Home<\/code> component.<\/p>\n<p>Inside the <code>Home<\/code> component, we start by setting an initial state for the options. Then we create a new instance of an avatar using the <code>generate<\/code> method provided by <code>faces<\/code>. After that, we have a <code>useEffect<\/code> hook to make update the avatar being displayed every time an option is updated. Next, there is the <code>updateAvatar<\/code> function that will get called each time a form value is changed.<\/p>\n<p>We do a little object trick in this function to only update the value that has been changed instead of needing to update all of the values. Then we start adding components to the return statement here. The main things we return are the form and the <code>&lt;div&gt;<\/code> that the <code>faces<\/code> library targets in the <code>display<\/code> method called in the <code>useEffect<\/code> hook.<\/p>\n<p>That\u2019s actually all we have to do for this app! Now you can play around with the avatars that get generated.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/res.cloudinary.com\/mediadevs\/image\/upload\/c_limit,w_2000\/f_auto\/q_auto\/v1656343011\/e-603fc55d218a650069f5228b\/gvepuzwfcou9uvuy4efr.png\" alt=\"complete avatar app\" loading=\"lazy\" class=\"c-transformed-asset\"  width=\"1792\" height=\"1882\"\/><\/p>\n<h2>Finished code<\/h2>\n<p>You can check out all of the code in the <code>qr-card<\/code> folder of <a href=\"https:\/\/github.com\/flippedcoder\/media-projects\/tree\/main\/cartoon-avatar\">this repo<\/a>. You can also check out the app in <a href=\"https:\/\/codesandbox.io\/s\/elated-leaf-s5di51\">this Code Sandbox<\/a>.<\/p>\n<p>&lt;CodeSandBox\ntitle=\u201celated-leaf-s5di51\u201d\nid=\u201celated-leaf-s5di51\u201d\n\/&gt;<\/p>\n<h2>Conclusion<\/h2>\n<p>There are a lot of ways to practice your JavaScript skills. For example, how would you have handled that object that gets updated based on a dynamic value? These are the little things that make app building a little faster every time you go through the process. Except in this case, instead of worrying about what happens in production, you get to see if your experiments work by looking at your avatar.<\/p>\n<\/div>","protected":false},"excerpt":{"rendered":"","protected":false},"author":41,"featured_media":28527,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_cloudinary_featured_overwrite":false,"footnotes":""},"categories":[1],"tags":[134,370,212,246,371],"class_list":["post-28526","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-guest-post","tag-image","tag-next-js","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>Generate Cartoon Avatars in NextJS<\/title>\n<meta name=\"description\" content=\"In this post, we&#039;ll go over a common form implementation in Next to make a cartoon avatar generator. You&#039;ll see one of the ways you can dynamically update a component based on users playing around with inputs.\" \/>\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\/generate-cartoon-avatars-in-next\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Generate Cartoon Avatars in NextJS\" \/>\n<meta property=\"og:description\" content=\"In this post, we&#039;ll go over a common form implementation in Next to make a cartoon avatar generator. You&#039;ll see one of the ways you can dynamically update a component based on users playing around with inputs.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/cloudinary.com\/blog\/guest_post\/generate-cartoon-avatars-in-next\/\" \/>\n<meta property=\"og:site_name\" content=\"Cloudinary Blog\" \/>\n<meta property=\"article:published_time\" content=\"2022-06-28T10:19:51+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-02-24T23:14:13+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/v1681924241\/Web_Assets\/blog\/cc5c6a4b1e522ca1e14b7edfd9afcc592b8ecf21-6000x4000-1_28527a83c7\/cc5c6a4b1e522ca1e14b7edfd9afcc592b8ecf21-6000x4000-1_28527a83c7-jpg?_i=AA\" \/>\n\t<meta property=\"og:image:width\" content=\"6000\" \/>\n\t<meta property=\"og:image:height\" content=\"4000\" \/>\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\/guest_post\/generate-cartoon-avatars-in-next\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/generate-cartoon-avatars-in-next\/\"},\"author\":{\"name\":\"\",\"@id\":\"\"},\"headline\":\"Generate Cartoon Avatars in NextJS\",\"datePublished\":\"2022-06-28T10:19:51+00:00\",\"dateModified\":\"2025-02-24T23:14:13+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/generate-cartoon-avatars-in-next\/\"},\"wordCount\":5,\"publisher\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/generate-cartoon-avatars-in-next\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681924241\/Web_Assets\/blog\/cc5c6a4b1e522ca1e14b7edfd9afcc592b8ecf21-6000x4000-1_28527a83c7\/cc5c6a4b1e522ca1e14b7edfd9afcc592b8ecf21-6000x4000-1_28527a83c7.jpg?_i=AA\",\"keywords\":[\"Guest Post\",\"Image\",\"Next.js\",\"React\",\"Under Review\"],\"inLanguage\":\"en-US\",\"copyrightYear\":\"2022\",\"copyrightHolder\":{\"@id\":\"https:\/\/cloudinary.com\/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/generate-cartoon-avatars-in-next\/\",\"url\":\"https:\/\/cloudinary.com\/blog\/guest_post\/generate-cartoon-avatars-in-next\/\",\"name\":\"Generate Cartoon Avatars in NextJS\",\"isPartOf\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/generate-cartoon-avatars-in-next\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/generate-cartoon-avatars-in-next\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681924241\/Web_Assets\/blog\/cc5c6a4b1e522ca1e14b7edfd9afcc592b8ecf21-6000x4000-1_28527a83c7\/cc5c6a4b1e522ca1e14b7edfd9afcc592b8ecf21-6000x4000-1_28527a83c7.jpg?_i=AA\",\"datePublished\":\"2022-06-28T10:19:51+00:00\",\"dateModified\":\"2025-02-24T23:14:13+00:00\",\"description\":\"In this post, we'll go over a common form implementation in Next to make a cartoon avatar generator. You'll see one of the ways you can dynamically update a component based on users playing around with inputs.\",\"breadcrumb\":{\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/generate-cartoon-avatars-in-next\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/cloudinary.com\/blog\/guest_post\/generate-cartoon-avatars-in-next\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/generate-cartoon-avatars-in-next\/#primaryimage\",\"url\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681924241\/Web_Assets\/blog\/cc5c6a4b1e522ca1e14b7edfd9afcc592b8ecf21-6000x4000-1_28527a83c7\/cc5c6a4b1e522ca1e14b7edfd9afcc592b8ecf21-6000x4000-1_28527a83c7.jpg?_i=AA\",\"contentUrl\":\"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681924241\/Web_Assets\/blog\/cc5c6a4b1e522ca1e14b7edfd9afcc592b8ecf21-6000x4000-1_28527a83c7\/cc5c6a4b1e522ca1e14b7edfd9afcc592b8ecf21-6000x4000-1_28527a83c7.jpg?_i=AA\",\"width\":6000,\"height\":4000},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/cloudinary.com\/blog\/guest_post\/generate-cartoon-avatars-in-next\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/cloudinary.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Generate Cartoon Avatars in NextJS\"}]},{\"@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":"Generate Cartoon Avatars in NextJS","description":"In this post, we'll go over a common form implementation in Next to make a cartoon avatar generator. You'll see one of the ways you can dynamically update a component based on users playing around with inputs.","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\/generate-cartoon-avatars-in-next\/","og_locale":"en_US","og_type":"article","og_title":"Generate Cartoon Avatars in NextJS","og_description":"In this post, we'll go over a common form implementation in Next to make a cartoon avatar generator. You'll see one of the ways you can dynamically update a component based on users playing around with inputs.","og_url":"https:\/\/cloudinary.com\/blog\/guest_post\/generate-cartoon-avatars-in-next\/","og_site_name":"Cloudinary Blog","article_published_time":"2022-06-28T10:19:51+00:00","article_modified_time":"2025-02-24T23:14:13+00:00","og_image":[{"width":6000,"height":4000,"url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/v1681924241\/Web_Assets\/blog\/cc5c6a4b1e522ca1e14b7edfd9afcc592b8ecf21-6000x4000-1_28527a83c7\/cc5c6a4b1e522ca1e14b7edfd9afcc592b8ecf21-6000x4000-1_28527a83c7-jpg?_i=AA","type":"image\/jpeg"}],"twitter_card":"summary_large_image","schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"NewsArticle","@id":"https:\/\/cloudinary.com\/blog\/guest_post\/generate-cartoon-avatars-in-next\/#article","isPartOf":{"@id":"https:\/\/cloudinary.com\/blog\/guest_post\/generate-cartoon-avatars-in-next\/"},"author":{"name":"","@id":""},"headline":"Generate Cartoon Avatars in NextJS","datePublished":"2022-06-28T10:19:51+00:00","dateModified":"2025-02-24T23:14:13+00:00","mainEntityOfPage":{"@id":"https:\/\/cloudinary.com\/blog\/guest_post\/generate-cartoon-avatars-in-next\/"},"wordCount":5,"publisher":{"@id":"https:\/\/cloudinary.com\/blog\/#organization"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/guest_post\/generate-cartoon-avatars-in-next\/#primaryimage"},"thumbnailUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681924241\/Web_Assets\/blog\/cc5c6a4b1e522ca1e14b7edfd9afcc592b8ecf21-6000x4000-1_28527a83c7\/cc5c6a4b1e522ca1e14b7edfd9afcc592b8ecf21-6000x4000-1_28527a83c7.jpg?_i=AA","keywords":["Guest Post","Image","Next.js","React","Under Review"],"inLanguage":"en-US","copyrightYear":"2022","copyrightHolder":{"@id":"https:\/\/cloudinary.com\/#organization"}},{"@type":"WebPage","@id":"https:\/\/cloudinary.com\/blog\/guest_post\/generate-cartoon-avatars-in-next\/","url":"https:\/\/cloudinary.com\/blog\/guest_post\/generate-cartoon-avatars-in-next\/","name":"Generate Cartoon Avatars in NextJS","isPartOf":{"@id":"https:\/\/cloudinary.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/cloudinary.com\/blog\/guest_post\/generate-cartoon-avatars-in-next\/#primaryimage"},"image":{"@id":"https:\/\/cloudinary.com\/blog\/guest_post\/generate-cartoon-avatars-in-next\/#primaryimage"},"thumbnailUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681924241\/Web_Assets\/blog\/cc5c6a4b1e522ca1e14b7edfd9afcc592b8ecf21-6000x4000-1_28527a83c7\/cc5c6a4b1e522ca1e14b7edfd9afcc592b8ecf21-6000x4000-1_28527a83c7.jpg?_i=AA","datePublished":"2022-06-28T10:19:51+00:00","dateModified":"2025-02-24T23:14:13+00:00","description":"In this post, we'll go over a common form implementation in Next to make a cartoon avatar generator. You'll see one of the ways you can dynamically update a component based on users playing around with inputs.","breadcrumb":{"@id":"https:\/\/cloudinary.com\/blog\/guest_post\/generate-cartoon-avatars-in-next\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/cloudinary.com\/blog\/guest_post\/generate-cartoon-avatars-in-next\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/cloudinary.com\/blog\/guest_post\/generate-cartoon-avatars-in-next\/#primaryimage","url":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681924241\/Web_Assets\/blog\/cc5c6a4b1e522ca1e14b7edfd9afcc592b8ecf21-6000x4000-1_28527a83c7\/cc5c6a4b1e522ca1e14b7edfd9afcc592b8ecf21-6000x4000-1_28527a83c7.jpg?_i=AA","contentUrl":"https:\/\/res.cloudinary.com\/cloudinary-marketing\/images\/f_auto,q_auto\/v1681924241\/Web_Assets\/blog\/cc5c6a4b1e522ca1e14b7edfd9afcc592b8ecf21-6000x4000-1_28527a83c7\/cc5c6a4b1e522ca1e14b7edfd9afcc592b8ecf21-6000x4000-1_28527a83c7.jpg?_i=AA","width":6000,"height":4000},{"@type":"BreadcrumbList","@id":"https:\/\/cloudinary.com\/blog\/guest_post\/generate-cartoon-avatars-in-next\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/cloudinary.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Generate Cartoon Avatars in NextJS"}]},{"@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\/v1681924241\/Web_Assets\/blog\/cc5c6a4b1e522ca1e14b7edfd9afcc592b8ecf21-6000x4000-1_28527a83c7\/cc5c6a4b1e522ca1e14b7edfd9afcc592b8ecf21-6000x4000-1_28527a83c7.jpg?_i=AA","_links":{"self":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/28526","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=28526"}],"version-history":[{"count":1,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/28526\/revisions"}],"predecessor-version":[{"id":36997,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/posts\/28526\/revisions\/36997"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/media\/28527"}],"wp:attachment":[{"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/media?parent=28526"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/categories?post=28526"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cloudinary.com\/blog\/wp-json\/wp\/v2\/tags?post=28526"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}