Using images in Lovable
Learn how to add images to your Lovable projects
To add images you can do one of two things:
- Upload the image to the chat: Lovable will automatically use it in the project if relevant.
- Upload it to the github repository manually, outside of the Lovable UI
- Share an external image URL in the chat. a. Note: This will not work if the server hosting the URL has chosen to block external websites from using it with “CORS”
Below, we’ll walk you through the last two methods.
Using an external image URL
One way to add images to your project is by referencing an image from an external URL. This method allows you to use images hosted on external platforms like Unsplash, Imgur, or any other image-hosting service. Be mindful of use copyrights!
Here’s how to prompt Lovable to use an external image:
- First, find the image you want to use. For example, you can visit a site like Unsplash, select an image, and copy its URL.
- In your project prompt, simply tell Lovable to use that image by specifying the URL. For example:
Using images from your GitHub public
directory
Another method to add images to your Lovable project is by using images uploaded to the public
directory of your connected GitHub repository. Here’s how you can do it:
Connect your GitHub repository - Ensure your project is connected to your GitHub repo. Here’s how to connect your repo.
Locate the public folder - Inside your GitHub repository, navigate to the public
directory. This folder is typically used for hosting assets like images that can be referenced in your project.
Click on Add file and then from a dropdown, select Upload files option.
Upload an image - The next step is to transfer your image to your repo
-
Drag and drop the image into the public folder, or
-
Click on the “choose your files” link to browse and select the image file.
Commit the changes - After selecting your image, write a simple commit message (e.g., “Adding image files to be used in the app”) and click “Commit changes” to save the file to your repo.
Get the image path - Once the file is uploaded, select it and then click on the copy icon next to the file name to copy the image’s path. This path will be used in your Lovable prompt.
Use the image in Lovable - You can now reference this image in your project by using a prompt like the following:
Be sure to use your image name and path you copied in the previous step.
Uploading large images to your GitHub repo can cause it to grow in size, which can affect Lovable performance (longer repo cloning times, slower startup of previews/sandbox).
Try to optimize your images before uploading them to your public
folder by compressing them and using dimensions that are relevant to your use case. For example, don’t use a full HD-sized image if it will only be displayed as a small icon.
Explore more and learn from examples
To help you better understand how to integrate images using the methods outlined above, we have a project you can explore: Lovable Project Example. In this project, you can see the actual prompts and how each method works in practice.
Additionally, here’s a public GitHub repository that includes the commits, uploaded images, and full implementation details. You can view the repository here: GitHub: Adding Images Example.
Feel free to explore the project and repository to deepen your understanding and improve your implementation skills.