Photo cut

Creating a Social Media Campaign with PhotoCut API

Have you heard about the awesome marketing campaign for the new Barbie movie? It got super popular and everyone was sharing it on social media. And guess what? It was all thanks to PhotoCut’s Remove Background API! In this article, we're going to show you how you can make your web app with cool features like the Barbie campaign, using the PhotoCut API (and a little bit of JavaScript magic).

Download the app, NOW!

Trusted by teams around the world
A smiling girl surrounded by colorful emoticons, radiating joy and positivity in a vibrant atmosphere.

PhotoCut - A Game Changer!

Explore endless tools and templates at your fingertips to customize your new image using the PhotoCut app. They love us. You will too.

CAPTAIN SYKE

So much easy to use than the other apps that I have encountered. I'm so satisfied. I fished to clear the background less than a minute! Keep it up🙌🏻

Lee Willetts (Dr.Drone Doomstone)

Great app, used alongside text on photo, you can create some great pics. Hours of fun.

Bran Laser

I always erase and cut something with this it is very op there is no bug and I made a picture for my channel very nice install it now!

ZDX Gaming

The Best Photo Editor .. Not Many Can Actually Cut Pictures Perfectly Like this App been looking for something like this for a long time 💔😂 Nice App I recommend it Giving it 5 star

Small Optics

Best app of this type out there, it does nearly all of the work for you.. Great work developers.

Emilia Gacha

It's really useful and super easy to use and it may be the best background eraser app!

kymani ace

This is a really nice app I love how it let's me do lots of edits without paying for anything and there isn't even a watermark, very good app.

Nidhish Singh

Excellent apps and doing all the work as expected. Easy to use, navigate and apply to any background after cut out.

Adrian

Been using this app for many years now to crop photos and gotta say, really does what it's supposed to and makes photo's look realistic. Recommend it very much.

Indra Ismaya

Easy to use, very usefull

Barbie Dream

I love this app! You can edit and change the background i been using it for months for my video! Keep it going.

Kaira Binson

Ouh..finally i found a good app like this..after instalking 6-8 apps ..i finally get the right one...easy..free...so cool...but maybe pls..adjust your ads..in this app..thanks☺

Tara Coriell

I payed for premium but it was only a 1 time payment of 5.29 and I love this app. There are a lot of nice features

Engels Yepez

Great app for edit photos, it include an interesting IA function for apply effects to your pics

Azizah ahmad

This apps is awesome compared to other photo cut apps. I have tried several photo cut apps but all of them was bad. And finally i found this app, super easy to use, have feature smart cut and smart erase. Awesome !!

Galaxy Goat

The app is incredible! I erased a background and added it into a new background in less then 20 seconds. Normally it takes 10-20 minute's on other apps. Highly recommend

Victor Maldonado

I been having a few issues with app can't zoom in like before and its not like it use to what happen i paid for this app not liking the new upgrade

Lynsiah Sahuji

more accurate in removing background, didn't required so much effort. love this! ❤️

Step 1: Uploading an Image

  • First, let users pick the image they want to use. We can do this by using a simple <input> tag:

<input type="file" id="image-input" accept="image/*">

  • Next, we need to upload the file to PhotoCut’s API. It's easy because all we have to do is make a standard HTTP POST call:

async function removeBackground() {

    const formData = new FormData()

    formData.append("image_file", imageInput.files[0])

    formData.append("format", "png")

    const response = await fetch("https://sdk.photoroom.com/v1/segment", {

        method: "POST",

        headers: {

            "X-Api-Key": apiKey,

        },

        body: formData,

    })

    if (!response.ok) throw new Error("Failed to remove background")

    const blob = await response.blob()

    return await loadImage(blob)

}

Note - You must have an API key to make the API call.

Step 2: Putting the Image Together

Once we have the image with the background removed, we need to put it all together to make the final image.

  • The trick is to place the background-less image between a background and an overlay layer:
  • The code for this is in the drawImageWithOverlay() function:

async function drawImageWithOverlay(image, text, scaleFactor = 1, rotation = 0) {

    // load the backround and overlay images 

    const background = await loadLocalImage("assets/background.png")

    const overlay = await loadLocalImage("assets/overlay.png")

    const canvasHeight = 1920

    const canvasWidth = 1080

    const scale = Math.min(canvasWidth / image.width, canvasHeight / image.height)

    const scaledWidth = image.width * scale

    const scaledHeight = image.height * scale

    // create the canvas to compose the images

    const canvas = document.createElement("canvas")

    canvas.width = canvasWidth

    canvas.height = canvasHeight

    const ctx = canvas.getContext("2d")

    // Draw the background

    ctx.drawImage(background, 0, 0, canvasWidth, canvasHeight)

    // Adjust offsetX and offsetY to keep the image centered

    const offsetX = (canvasWidth - scaledWidth) / 2

    const offsetY = (canvasHeight - scaledHeight) / 2

    // Draw the image with the removed background

    ctx.drawImage(image, offsetX, offsetY, scaledWidth, scaledHeight)

  

    // Draw overlay on top

    ctx.drawImage(overlay, 0, 0, canvasWidth, canvasHeight)

    return canvas

}

This function might look a little complicated, we basically create a canvas, draw the background image, scale the user's image on top, and then add the overlay image.

Step 3: Adding Text

  • Now, we just need to let users add some text to the image. We can do this by using another <input> tag:

<label for="overlay-text" style="display: block; margin-bottom: 0.5rem;">This person is</label>

<input type="text" id="overlay-text" placeholder="Enter text overlay here..." maxlength="46">

  • The tricky part is drawing the text on the canvas with the right curvature. We need to add some code to the drawImageWithOverlay() function for this:

// Add text overlay

const fontSize = 58 // Increased font size

const curveRadius = 400 // Adjusted curve radius for less curvature

const centerX = canvasWidth / 2

const centerY = canvasHeight / 2 - 300

const whiteSpaceWidth = 15

const lineHeight = 58

ctx.font = `bold ${fontSize}px 'DM Sans', sans-serif`

ctx.fillStyle = "#000000"

const lines = ['This person is ', text]

let cursorPositionY = 0

// Iterate over each line of text

for (const line of lines) {

    const lineWidth = ctx.measureText(line).width

    const words = line.split(" ")

    const totalAngle = lineWidth / curveRadius

    const startAngle = (-Math.PI - totalAngle) / 2

    const endAngle = startAngle + totalAngle

    let cursorPositionX = 0

    // Iterate over each word in the line

    for (let i = 0; i < words.length; i++) {

        const word = words[i]

        // Iterate over each character in the word

        for (let j = 0; j < word.length; j++) {

            const char = word.charAt(j)

            const charWidth = ctx.measureText(char).width

            const x = cursorPositionX / lineWidth

            const angle = startAngle + x * (endAngle  - startAngle)

            ctx.save()

            ctx.translate(

                centerX + curveRadius * Math.cos(angle),

                centerY + curveRadius * Math.sin(angle) + cursorPositionY

            )

            ctx.rotate(Math.PI / 2 + angle)

            ctx.fillText(char, 0, 0)

            ctx.restore()

            cursorPositionX += charWidth

        }

        cursorPositionX += whiteSpaceWidth

    }

    cursorPositionY += lineHeight

}

This code might look complex but the idea is to go through each line of text, calculate the baseline, and draw each character with the correct rotation.

Step 4: Downloading the Image

We're almost done! We just need to add a button for users to download the final image and share it on social media:

  • First, we add a <button> to the HTML:

<a id="download-button" href="#" download="result.png" style="display: none;">

    <button>Download</button>

</a>

  • Then, we add the code to handle the download:

const finalImage = await drawImageWithOverlay(segmentedPhoto, text)

const downloadButton = document.getElementById("download-button")

finalImage.toBlob((blob) => {

    const url = URL.createObjectURL(blob)

    downloadButton.href = url

})

  • We take the canvas content, turn it into a binary file, and set the download link to that file.

Conclusion

And there you have it! With the PhotoCut API and a little bit of JavaScript, you can create a fun web app for users to upload selfies and customize them with cool visual assets.

With your branded assets in place of the backdrop, overlay, and text, you can even utilize this for your marketing campaign.

Visit our website's page on PhotoCut's API to find out more about your options!

FAQs

Q1: What is PhotoCut API?

Ans: The PhotoCut API is a powerful tool that allows developers to integrate advanced image editing features into their applications. It enables users to remove backgrounds, enhance images, and apply various graphic design elements, making it ideal for creating visually appealing content for social media campaigns.

Q2: How can the PhotoCut API be used in a social media campaign?

Ans: The PhotoCut API can be leveraged to enhance images for your social media posts. This includes background removal, image resizing, and applying filters. With these features, you can create professional-looking visuals that are tailored to your campaign's theme.

Q3: What are the steps to get started with the PhotoCut API?

Ans: To get started with the PhotoCut API, follow these steps:

  1. Sign Up: Create an account on the PhotoCut website and get API access.
  2. Review Documentation: Familiarize yourself with the API documentation to understand its endpoints and functionalities.
  3. Set Up Your Environment: Use your preferred programming language to make API calls.
  4. Integrate the API: Start building your application by integrating the PhotoCut API into your photo editing workflow for your campaign.

Q4: Are there any specific programming languages required to use the PhotoCut API?

Ans: No specific programming language is required. The PhotoCut API is RESTful, meaning you can use it with any language that can make HTTP requests, such as Python, JavaScript, PHP, Java, or Ruby.

Q5: Can I customize images using the PhotoCut API?

Ans: Yes! The PhotoCut API allows for a high degree of customization. You can adjust images by removing backgrounds, adding text overlays, and applying various filters or effects, making it easy to tailor images to fit your brand’s style and campaign needs.

Q6: How do I ensure the images created are optimized for different social media platforms?

Ans: The PhotoCut API provides features that allow you to resize images according to the specifications of different social media platforms. Refer to the platform-specific image guidelines (e.g., aspect ratio, resolution) and use the API’s resizing functionality to meet those requirements.

Q7: Can PhotoCut API handle bulk image processing for a campaign?

Ans: Yes, the PhotoCut API can process multiple images through batch processing, allowing you to enhance and edit large volumes of images efficiently. This is especially useful for campaigns with a large set of visuals.

Q8: What are the costs associated with using the PhotoCut API?

Ans: Pricing for the PhotoCut API may vary based on usage and subscription plans. For detailed information about pricing tiers and what features are included, visit the PhotoCut official website or check their pricing section in the documentation.

Q9: Is technical support available for developers using the PhotoCut API?

Ans: Yes, PhotoCut provides technical support for developers. You can access support resources such as FAQs, tutorials, and community forums, or contact their support team directly for assistance with integration and troubleshooting.

Q10: What is the best way to test the PhotoCut API before fully integrating it into a campaign?

Ans: PhotoCut API typically offers a sandbox or demo environment where you can test its functionalities without incurring charges. Use this environment to experiment with different features, make API calls, and ensure it meets your campaign requirements before full integration.

You might also be interested in

Explore our free tools

Make your pictures pop with features that are completely free.

FAQ’s

I recommend checking out our detailed step-by-step guide on How to Use a Free Photo Editor. It covers everything from downloading and installing to using the essential tools and techniques for enhancing your photos.