Watermarking Images Automation in Python

NeuralNine · Beginner ·💻 AI-Assisted Coding ·2y ago

Key Takeaways

The video demonstrates how to automate the process of watermarking images using Python, covering the necessary tools and techniques for image processing and automation.

Full Transcript

what is going on guys welcome back in this video today we're going to learn how to Watermark images using python so let us get right into [Music] it all right so we're going to learn how to automate watermarking images in Python today and the idea of watermarking is quite simple you maybe already know it from stock photos the ideas you have one or multiple uh original images and let's say you want to monetize them you took these images you're yourself you have the copyright to these images and now you want to monetize them you want to earn some money with them what you usually do is you add a watermark on top so that people cannot just use them by copying the images they can see here in this case neural 9.com with a couple of lines they can see what they would be buying if they want to pay money for it but they cannot just right click copy paste them they have to pay money so that you can provide them with the original image that's the basic idea of watermarking now let's say you are a photographer for example and you have 10,000 20,000 of these images that you want to Watermark of course it's quite tedious to open all of them in Photoshop or in and to do all of this watermarking manually so what we're going to do in this video today is we're going to learn how to automate this process with python so how we can actually take a lot of images and just water mark them by calling a simple function so we're going to do this here by using One external python package the only package we're going to use in this video today which is pillow so we're going to use pip pip or pip 3 to install pillow and our only import is going to be from P so Capital pil pillow import image image draw and image font and then we're going to define a function at Watermark overlay and this function will take three parameters input image path output image path and Watermark text which in my case was neur online.com but of course you can change that to whatever you need so the input image will be loaded by using image. openen input image path and then we're going to convert this to rgba so I'm going to say input image convert rgba red green blue and uh I don't know what a actually stands for but it's opacity basically so transparency uh I think alpha alpha Channel um so rgba and then we're going to say the width and the height of this image is the input image uh size so this is going to give us a tupal of width and height now we need that to find the center of the image where we're going to place everything but first of all we need to create an overlay which is going to be image. new and we're going to just say here that it's going to have the rgba uh color system we're going to say input image size is going to be the size of this overlay and we're going to set this to 255 255 255 with zero opacity so basically white with zero opacity um and what we want to do now is want to say a draw object is going to be image draw draw overlay and on this overlay we're going to draw certain things like the lines and um also the text and for the lines we're going to define a color so Watermark color pattern is going to be equal to 255 255 255 and an opacity of 30 then what we're going to do is we're going to draw the diagonal lines we're going to say 4 I in range zero up until width plus height with a step size of 50 we're we're going to say draw line and here we're going to pass now zero height minus I I height I'm going to say fill is going to be equal to the watermark color pattern the width is going to be equal to five so this is just drawing the uh diagonal lines and then we're going to set the font size equal to 80 and the font is going to be an image font. true type uh arial.ttf now it's lagging again thanks for that and font size here and then we're going to say text width and text height is going to be equal to to draw. text size um Watermark text and font like this um and then what we're going to do is we're going to calculate the center of the image where we're going to place the text so we're going to say x is equal to width minus text width by the way please excuse my voice I'm still quite cold uh as you probably notice um and then we're going to say here Y is height minus text height / by two and then we're going to define the color for the text Watermark color text is going to be equal to 255 255 255 with 80 opacity and and then we're going to say draw. text X and Y actually this is a tle here um Watermark text is the text itself and the color is going to be Watermark color text the font is going to be equal to font and then the watermarked image is going to be equal to image Alpha composite input image and overlay and finally to just output this image we're going to say Watermark image save output image path and now we can just call this function by saying input image path is equal to input image now I'm going to delete the output image so that we can generate it again so input image path is input image JPEG the output image path um needs to be a PNG file I think even though I'm not exactly sure but I think it has to be PNG because of the alpha channel uh we're going to say output image.png and the watermark text will be YouTube tutorial and then we can just call add Mark overlay um and we can just pass these things input image path output image path Watermark text so let's run this we get a warning and there you go our image is watermarked with YouTube tutorial now I only have one image here now but automating this for many images is very very simple all you would have to do is you would have to import OS you would have to get a directory here here with images then you would say something like for file in sorry for file in OS list directory images you would just say um you could just say something like uh add Watermark overlay file or actually you would have to say images and then file and then the output would be something like images or maybe you create another directory output images or something and then you say maybe something like file uh maybe you could say here watermarked file and then you replace the jpack with PNG in case you have to um what's the problem here oh we have to use double quote not ation in the F string uh but yeah basically you can do that and you want to use of course the watermark text which is uh you know norline or something so in this case you could try that you could just paste this here I can run the script no such file in directory yes because I'm still running this here but there you go you can automate this for as many images as you want so that's it for today's video I hope you enjoyed it and hope you learned something if so let me know by hitting a like button and leaving a comment in the comment section down below and of course don't forget to subscribe to this Channel and hit the notification Bell to not miss a single future video for free other than that thank you much for watching see you in the next video and bye

Original Description

Today we learn how to automate the process of watermarking images in Python. ◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾ 📚 Programming Books & Merch 📚 🐍 The Python Bible Book: https://www.neuralnine.com/books/ 💻 The Algorithm Bible Book: https://www.neuralnine.com/books/ 👕 Programming Merch: https://www.neuralnine.com/shop 💼 Services 💼 💻 Freelancing & Tutoring: https://www.neuralnine.com/services 🌐 Social Media & Contact 🌐 📱 Website: https://www.neuralnine.com/ 📷 Instagram: https://www.instagram.com/neuralnine 🐦 Twitter: https://twitter.com/neuralnine 🤵 LinkedIn: https://www.linkedin.com/company/neuralnine/ 📁 GitHub: https://github.com/NeuralNine 🎙 Discord: https://discord.gg/JU4xr8U3dm
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from NeuralNine · NeuralNine · 0 of 60

← Previous Next →
1 Visualizing Stock Data With Candlestick Charts in Python
Visualizing Stock Data With Candlestick Charts in Python
NeuralNine
2 Python Beginner Tutorial #1 - Installation and First Program
Python Beginner Tutorial #1 - Installation and First Program
NeuralNine
3 Python Beginner Tutorial #2 - Variables and Data Types
Python Beginner Tutorial #2 - Variables and Data Types
NeuralNine
4 Python Beginner Tutorial #3 - Operators and User Input
Python Beginner Tutorial #3 - Operators and User Input
NeuralNine
5 Python Beginner Tutorial #4 - If Statements and Conditions
Python Beginner Tutorial #4 - If Statements and Conditions
NeuralNine
6 Python Beginner Tutorial #5 - Loops
Python Beginner Tutorial #5 - Loops
NeuralNine
7 Python Beginner Tutorial #6 - Sequences and Collections
Python Beginner Tutorial #6 - Sequences and Collections
NeuralNine
8 Python Beginner Tutorial #7 - Functions
Python Beginner Tutorial #7 - Functions
NeuralNine
9 Python Beginner Tutorial #8 - Exception Handling
Python Beginner Tutorial #8 - Exception Handling
NeuralNine
10 Python Beginner Tutorial #9 - File Operations
Python Beginner Tutorial #9 - File Operations
NeuralNine
11 Python Beginner Tutorial #10 - String Functions
Python Beginner Tutorial #10 - String Functions
NeuralNine
12 Python Intermediate Tutorial #1 - Classes and Objects
Python Intermediate Tutorial #1 - Classes and Objects
NeuralNine
13 Python Intermediate Tutorial #2 - Inheritance
Python Intermediate Tutorial #2 - Inheritance
NeuralNine
14 Python Intermediate Tutorial #3 - Multithreading
Python Intermediate Tutorial #3 - Multithreading
NeuralNine
15 Python Intermediate Tutorial #4 - Synchronizing Threads
Python Intermediate Tutorial #4 - Synchronizing Threads
NeuralNine
16 Python Intermediate Tutorial #5 - Events and Daemon Threads
Python Intermediate Tutorial #5 - Events and Daemon Threads
NeuralNine
17 Python Intermediate Tutorial #6 - Queues
Python Intermediate Tutorial #6 - Queues
NeuralNine
18 Python Intermediate Tutorial #7 - Sockets and Network Programming
Python Intermediate Tutorial #7 - Sockets and Network Programming
NeuralNine
19 Python Intermediate Tutorial #8 - Database Programming
Python Intermediate Tutorial #8 - Database Programming
NeuralNine
20 Python Intermediate Tutorial #9 - Recursion
Python Intermediate Tutorial #9 - Recursion
NeuralNine
21 Python Intermediate Tutorial #10 - XML Processing
Python Intermediate Tutorial #10 - XML Processing
NeuralNine
22 Python Intermediate Tutorial #11 - Logging
Python Intermediate Tutorial #11 - Logging
NeuralNine
23 Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
NeuralNine
24 Python Data Science Tutorial #2 - NumPy Arrays
Python Data Science Tutorial #2 - NumPy Arrays
NeuralNine
25 Python Data Science Tutorial #3 - Numpy Functions
Python Data Science Tutorial #3 - Numpy Functions
NeuralNine
26 Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
NeuralNine
27 Python Data Science Tutorial #5 - Subplots and Multiple Windows
Python Data Science Tutorial #5 - Subplots and Multiple Windows
NeuralNine
28 Python Data Science Tutorial #6 - Matplotlib Styling
Python Data Science Tutorial #6 - Matplotlib Styling
NeuralNine
29 Python Data Science Tutorial #7 - Bar Charts with Matplotlib
Python Data Science Tutorial #7 - Bar Charts with Matplotlib
NeuralNine
30 Python Data Science Tutorial #8 - Pie Charts with Matplotlib
Python Data Science Tutorial #8 - Pie Charts with Matplotlib
NeuralNine
31 Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
NeuralNine
32 Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
NeuralNine
33 Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
NeuralNine
34 Python Data Science Tutorial #12 - Pandas Series
Python Data Science Tutorial #12 - Pandas Series
NeuralNine
35 Python Data Science Tutorial #13 - Pandas Data Frames
Python Data Science Tutorial #13 - Pandas Data Frames
NeuralNine
36 Python Data Science Tutorial #14 - Pandas Statistics
Python Data Science Tutorial #14 - Pandas Statistics
NeuralNine
37 Python Data Science Tutorial #15 - Pandas Sorting and Functions
Python Data Science Tutorial #15 - Pandas Sorting and Functions
NeuralNine
38 Python Data Science Tutorial #16 - Pandas Merging Data Frames
Python Data Science Tutorial #16 - Pandas Merging Data Frames
NeuralNine
39 Python Data Science Tutorial #17 - Pandas Queries
Python Data Science Tutorial #17 - Pandas Queries
NeuralNine
40 Python Machine Learning Tutorial #1 - What is Machine Learning?
Python Machine Learning Tutorial #1 - What is Machine Learning?
NeuralNine
41 Python Machine Learning Tutorial #2 - Linear Regression
Python Machine Learning Tutorial #2 - Linear Regression
NeuralNine
42 Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
NeuralNine
43 Python Machine Learning #4 - Support Vector Machines
Python Machine Learning #4 - Support Vector Machines
NeuralNine
44 Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
NeuralNine
45 Python Machine Learning Tutorial #6 - K-Means Clustering
Python Machine Learning Tutorial #6 - K-Means Clustering
NeuralNine
46 Python Machine Learning Tutorial #7 - Neural Networks
Python Machine Learning Tutorial #7 - Neural Networks
NeuralNine
47 Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
NeuralNine
48 Generating Poetic Texts with Recurrent Neural Networks in Python
Generating Poetic Texts with Recurrent Neural Networks in Python
NeuralNine
49 Stock Portfolio Visualization with Matplotlib in Python
Stock Portfolio Visualization with Matplotlib in Python
NeuralNine
50 Analyzing Coronavirus with Python (COVID-19)
Analyzing Coronavirus with Python (COVID-19)
NeuralNine
51 Making Text Images Readable Again with Python and OpenCV
Making Text Images Readable Again with Python and OpenCV
NeuralNine
52 Neural Networks Simply Explained (Theory)
Neural Networks Simply Explained (Theory)
NeuralNine
53 Motion Filtering with OpenCV in Python
Motion Filtering with OpenCV in Python
NeuralNine
54 Top 5 Programming Languages To Learn in 2020
Top 5 Programming Languages To Learn in 2020
NeuralNine
55 Simple TCP Chat Room in Python
Simple TCP Chat Room in Python
NeuralNine
56 Image Classification with Neural Networks in Python
Image Classification with Neural Networks in Python
NeuralNine
57 Edge Detection with OpenCV in Python
Edge Detection with OpenCV in Python
NeuralNine
58 S&P 500 Web Scraping with Python
S&P 500 Web Scraping with Python
NeuralNine
59 Simple Sentiment Text Analysis in Python
Simple Sentiment Text Analysis in Python
NeuralNine
60 Introduction - Algorithms & Data Structures #1
Introduction - Algorithms & Data Structures #1
NeuralNine

This video teaches how to automate image watermarking using Python, covering the necessary tools and techniques for image processing and automation. By the end of the video, viewers will be able to automate the process of watermarking images using Python. The video is suitable for beginners with basic knowledge of Python programming.

Key Takeaways
  1. Install necessary libraries such as Pillow or OpenCV
  2. Load the image to be watermarked
  3. Create or load the watermark image
  4. Position and resize the watermark
  5. Apply the watermark to the image
  6. Save the watermarked image
💡 The video highlights the importance of automation in image processing and provides a practical example of how to achieve this using Python.

Related Reads

📰
Breaking the Physical Wall: The Ultimate Guide to Heterogeneous AI Parallelism on Android
Learn to break the physical wall of AI parallelism on Android with heterogeneous computing, enabling faster and more efficient ML processing
Dev.to · Programming Central
📰
What is Vibecoding and Why It Will Change How You Build Things
Vibecoding is a new approach to building things, focusing on the emotional and intuitive aspects of coding, and it's going to change how you build things
Medium · Programming
📰
How to Make Claude Code Follow Your Project Rules
Learn to make Claude code follow your project rules by creating a CLAUDE.md file and defining specific rules for frontend and backend development
Medium · JavaScript
📰
A Dash of dev.to: My Blog Stats Now Live in the Terminal
Learn how to bring Dev.to blog stats into your terminal using a custom tool, and discover the benefits of integrating AI-powered code review into your workflow
Dev.to · Athreya aka Maneshwar
Up next
What is Claude Code? | Claude Code Episode 01
Ascent
Watch →