Watermarking Images Automation in Python
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
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Visualizing Stock Data With Candlestick Charts in Python
NeuralNine
Python Beginner Tutorial #1 - Installation and First Program
NeuralNine
Python Beginner Tutorial #2 - Variables and Data Types
NeuralNine
Python Beginner Tutorial #3 - Operators and User Input
NeuralNine
Python Beginner Tutorial #4 - If Statements and Conditions
NeuralNine
Python Beginner Tutorial #5 - Loops
NeuralNine
Python Beginner Tutorial #6 - Sequences and Collections
NeuralNine
Python Beginner Tutorial #7 - Functions
NeuralNine
Python Beginner Tutorial #8 - Exception Handling
NeuralNine
Python Beginner Tutorial #9 - File Operations
NeuralNine
Python Beginner Tutorial #10 - String Functions
NeuralNine
Python Intermediate Tutorial #1 - Classes and Objects
NeuralNine
Python Intermediate Tutorial #2 - Inheritance
NeuralNine
Python Intermediate Tutorial #3 - Multithreading
NeuralNine
Python Intermediate Tutorial #4 - Synchronizing Threads
NeuralNine
Python Intermediate Tutorial #5 - Events and Daemon Threads
NeuralNine
Python Intermediate Tutorial #6 - Queues
NeuralNine
Python Intermediate Tutorial #7 - Sockets and Network Programming
NeuralNine
Python Intermediate Tutorial #8 - Database Programming
NeuralNine
Python Intermediate Tutorial #9 - Recursion
NeuralNine
Python Intermediate Tutorial #10 - XML Processing
NeuralNine
Python Intermediate Tutorial #11 - Logging
NeuralNine
Python Data Science Tutorial #1 - Anaconda and PyCharm Setup
NeuralNine
Python Data Science Tutorial #2 - NumPy Arrays
NeuralNine
Python Data Science Tutorial #3 - Numpy Functions
NeuralNine
Python Data Science Tutorial #4 - Plotting Functions With Matplotlib
NeuralNine
Python Data Science Tutorial #5 - Subplots and Multiple Windows
NeuralNine
Python Data Science Tutorial #6 - Matplotlib Styling
NeuralNine
Python Data Science Tutorial #7 - Bar Charts with Matplotlib
NeuralNine
Python Data Science Tutorial #8 - Pie Charts with Matplotlib
NeuralNine
Python Data Science Tutorial #9 - Plotting Histograms with Matplotlib
NeuralNine
Python Data Science Tutorial #10 - Scatter Plots with Matplotlib
NeuralNine
Python Data Science Tutorial #11 - 3D Plotting with Matplotlib
NeuralNine
Python Data Science Tutorial #12 - Pandas Series
NeuralNine
Python Data Science Tutorial #13 - Pandas Data Frames
NeuralNine
Python Data Science Tutorial #14 - Pandas Statistics
NeuralNine
Python Data Science Tutorial #15 - Pandas Sorting and Functions
NeuralNine
Python Data Science Tutorial #16 - Pandas Merging Data Frames
NeuralNine
Python Data Science Tutorial #17 - Pandas Queries
NeuralNine
Python Machine Learning Tutorial #1 - What is Machine Learning?
NeuralNine
Python Machine Learning Tutorial #2 - Linear Regression
NeuralNine
Python Machine Learning Tutorial #3 - K-Nearest Neighbors Classification
NeuralNine
Python Machine Learning #4 - Support Vector Machines
NeuralNine
Python Machine Learning Tutorial #5 - Decision Trees and Random Forest Classification
NeuralNine
Python Machine Learning Tutorial #6 - K-Means Clustering
NeuralNine
Python Machine Learning Tutorial #7 - Neural Networks
NeuralNine
Python Machine Learning Tutorial #8 - Handwritten Digit Recognition with Tensorflow
NeuralNine
Generating Poetic Texts with Recurrent Neural Networks in Python
NeuralNine
Stock Portfolio Visualization with Matplotlib in Python
NeuralNine
Analyzing Coronavirus with Python (COVID-19)
NeuralNine
Making Text Images Readable Again with Python and OpenCV
NeuralNine
Neural Networks Simply Explained (Theory)
NeuralNine
Motion Filtering with OpenCV in Python
NeuralNine
Top 5 Programming Languages To Learn in 2020
NeuralNine
Simple TCP Chat Room in Python
NeuralNine
Image Classification with Neural Networks in Python
NeuralNine
Edge Detection with OpenCV in Python
NeuralNine
S&P 500 Web Scraping with Python
NeuralNine
Simple Sentiment Text Analysis in Python
NeuralNine
Introduction - Algorithms & Data Structures #1
NeuralNine
More on: AI Pair Programming
View skill →Related Reads
📰
📰
📰
📰
Breaking the Physical Wall: The Ultimate Guide to Heterogeneous AI Parallelism on Android
Dev.to · Programming Central
What is Vibecoding and Why It Will Change How You Build Things
Medium · Programming
How to Make Claude Code Follow Your Project Rules
Medium · JavaScript
A Dash of dev.to: My Blog Stats Now Live in the Terminal
Dev.to · Athreya aka Maneshwar
🎓
Tutor Explanation
DeepCamp AI