Skip to content

Commit d111c21

Browse files
committed
🎨 Add addLogo
1 parent 5feba26 commit d111c21

File tree

3 files changed

+97
-0
lines changed

3 files changed

+97
-0
lines changed

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ pip install -r requirements.txt
4646
- [Combine PDF files](#Combine-PDF-files)
4747
- [Add Watermark to PDF](#Add-Watermark-to-PDF)
4848
- [Encrypt or Decrypt a PDF](#Encrypt-or-Decrypt-a-PDF)
49+
- [Add Logo to Images](#Add-Logo-to-Images)
4950

5051
### Code Destroyer
5152

@@ -67,6 +68,8 @@ Enter the full filename (like helloWorld.c) in the prompt that follows.
6768

6869
Takes in the text from your clipboard and saves the Phone Numbers and Email Addresses found in it to .txt files. It searches for Indian Mobile Phone Numbers, Toll-Free Numbers, Telephone Numbers and Emails using Regular Expressions.
6970

71+
_Useful if you have a large text data (like a website) and you are searching for phone numbers of emails in that text._
72+
7073
#### Usage:
7174

7275
```py3
@@ -79,6 +82,8 @@ Two files, `emails.txt` and `phoneNumbers.txt` would be created in the same dire
7982

8083
Lets you search through a folder based on file size. Asks user for folder path and size. Files and subfolders inside the folder, greater than or equal to the input size would be displayed.
8184

85+
_Useful if you want to find large files and folders taking up space and wish to delete them._
86+
8287
#### Usage:
8388

8489
```py3
@@ -91,6 +96,8 @@ When prompted, enter the minimum size (in bytes) and the folder where files are
9196

9297
Finds all files with a given prefix, such as spam001.txt, spam002.txt, and so on, in a single folder and locates any gaps in the numbering (such as if there is a spam001.txt and spam003.txt but no spam002.txt) and reanames all the files to close this gap.
9398

99+
_Useful if you have a number of files with same prefix and numbering after it and by some case, there is irregularity in numbering (like after deleting unnecessary images from a camera) and you wish to get a ragular naming in those files._
100+
94101
#### Usage:
95102

96103
```py3
@@ -108,6 +115,8 @@ a single PDF. The program also prompts user if they want to include the cover pa
108115
It is recommended to rename files so that they are lexographically in the same order as they are to be combined and put them in the same directory as the script.
109116
The combined PDF would be saved as the name of the first file in the lexographic order prepended with 'combined'.
110117

118+
_Useful if you have many PDF and you want to read them all one after the another (like PDFs of a professor's slides that you wish to read before exams). You won't need to go from one PDF to another._
119+
111120
__Ensure that none of the PDFs are encrypted.__
112121

113122
#### Usage:
@@ -124,6 +133,8 @@ Add watermark to every page of a PDF document.
124133

125134
The watermark file should be a PDF too. If you want to make an image or text as a watermark, put them in a word file and stylize as per you want it to appear as the watermark and then export the file as PDF. This file would be the watermark file.
126135

136+
_The usefullness of this script is straightforward - To add watermark to PDF files to prove its originality, make it harder to copy, and add authorship._
137+
127138
__Ensure that none of the PDFs are encrypted.__
128139

129140
#### Usage:
@@ -138,6 +149,8 @@ Enter the filenames of the PDF to be watermarked and then of the watermark PDF.
138149

139150
Encrypt an unencrypted PDF file with a password or decrypt a password-protected PDF and save as an unencrypted file.
140151

152+
_The usefullness of this script too is pretty straightforward - To add or remove privacy to PDF files._
153+
141154
#### Usage:
142155

143156
```py3
@@ -146,6 +159,20 @@ python3 encryptDecryptPDF.py
146159

147160
Choose whether you want to encrypt or decrypt a PDF and then enter the name of the file. You would be prompted to enter the password either to encrypt the PDF or decrypt it, as selected earlier.
148161

162+
### Add Logo to Images
163+
164+
Adds logo to the lower-right corner of all the pngs, jpgs and jpegs in the directory.
165+
166+
_Useful to add logos to imagesto prove their originality, make them harder to copy, and add authorship._
167+
#### Usage:
168+
169+
```py3
170+
python3 addLogo.py
171+
```
172+
173+
Enter the location of the logo file in the prompt that follows. All the images with added logo would be saved in the 'withLogo' directory.
174+
175+
149176
## License
150177

151178
[MIT License](LICENSE)

addLogo/addLogo.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
"""
2+
addLogo.py - Adds logo to the lower-right corner of all the png, jpg, jpeg
3+
files in the directory.
4+
5+
Usage: run "python3 addLogo.py" and enter the name of the logo to be inserted.
6+
All the images with added logo would be saved in 'withLogo' directory.
7+
"""
8+
9+
import os
10+
import sys
11+
from PIL import Image
12+
13+
logoName = input('Enter the name of the logo image:\n')
14+
logoName = os.path.abspath(logoName)
15+
16+
# If logo file does not ecists or is not a supported image file
17+
if not os.path.exists(logoName):
18+
print('The filename ' + logoName + ' does not exists.')
19+
sys.exit()
20+
elif not (logoName.lower().endswith('.png') or \
21+
logoName.lower().endswith('.jpg') or logoName.lower().endswith('.jpeg')):
22+
print('The filename ' + logoName + ' is not a supported image file.')
23+
sys.exit()
24+
25+
logoIm = Image.open(logoName).convert("RGBA")
26+
logoWidth, logoHeight = logoIm.size
27+
os.makedirs('withLogo', exist_ok = True)
28+
29+
# Loop over all files in the working directory
30+
for fileName in os.listdir('.'):
31+
if not (fileName.lower().endswith('.png') or \
32+
fileName.lower().endswith('.jpg') or \
33+
fileName.lower().endswith('.jpeg')) or \
34+
os.path.abspath(fileName) == logoName:
35+
continue # skip non-image files and the logo file itself
36+
37+
im = Image.open(fileName)
38+
width, height = im.size
39+
40+
# Resizes the largest dimention of logo to 1/5 of smallest dimension
41+
# of the image file
42+
if height < width:
43+
if logoWidth > logoHeight:
44+
logoHeight = int((logoHeight / logoWidth) * int(height/10))
45+
logoWidth = int(height/10)
46+
else:
47+
logoWidth = int((logoWidth / logoHeight) * int(height/10))
48+
logoHeight = int(height/10)
49+
pad = int(height/25)
50+
else:
51+
if logoWidth > logoHeight:
52+
logoHeight = int((logoHeight / logoWidth) * int(width/10))
53+
logoWidth = int(width/10)
54+
else:
55+
logoWidth = int((logoWidth / logoHeight) * int(width/10))
56+
logoHeight = int(width/10)
57+
pad = int(height/25)
58+
59+
# Resize the logo
60+
logoIm = logoIm.resize((logoWidth, logoHeight), Image.ANTIALIAS)
61+
62+
# Add logo
63+
print(f'Adding logo to {fileName}...')
64+
im.paste(logoIm, (width - logoWidth - pad, height - logoHeight - pad), \
65+
logoIm)
66+
67+
# Save the image with added logo
68+
im.save(os.path.join('withLogo', fileName), quality = 100)
69+
print(f'Saved {fileName} with added logo.')

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
pyperclip==1.7.0
2+
Pillow==6.1.0
23
PyPDF3==1.0.1

0 commit comments

Comments
 (0)