Skip to content

Simplify Boolean Expressions Using startswith and endswith #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 32 additions & 32 deletions add_logo_to_images.py
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import os
from PIL import Image
#LOGO_FILENAME = 'catlogo.png'
LOGO_FILENAME = input('Enter The Logo Name With Extension: ')
NEW_FOLDER_NAME = input("Enter The New Folder Name : ")
logoIm = Image.open(LOGO_FILENAME)
logoWidth, logoHeight = logoIm.size
os.makedirs(NEW_FOLDER_NAME, exist_ok=True)
# Loop over all files in the working directory.
for filename in os.listdir('.'):
if not (filename.endswith('.png') or filename.endswith('.jpg')) \
or filename == LOGO_FILENAME:
continue # skip non-image files and the logo file itself
im = Image.open(filename)
width, height = im.size
# Add logo.
print('Adding logo to %s...' % (filename))
im.paste(logoIm, (width - logoWidth, height - logoHeight), logoIm)
# Save changes.
im.save(os.path.join(NEW_FOLDER_NAME, filename))
print("Done Adding Logo To All Images ... ^_^")


import os
from PIL import Image


#LOGO_FILENAME = 'catlogo.png'
LOGO_FILENAME = input('Enter The Logo Name With Extension: ')
NEW_FOLDER_NAME = input("Enter The New Folder Name : ")

logoIm = Image.open(LOGO_FILENAME)
logoWidth, logoHeight = logoIm.size

os.makedirs(NEW_FOLDER_NAME, exist_ok=True)
# Loop over all files in the working directory.
for filename in os.listdir('.'):
if not filename.endswith(('.png', '.jpg')) \
or filename == LOGO_FILENAME:
continue # skip non-image files and the logo file itself

im = Image.open(filename)
width, height = im.size


# Add logo.
print('Adding logo to %s...' % (filename))
im.paste(logoIm, (width - logoWidth, height - logoHeight), logoIm)

# Save changes.
im.save(os.path.join(NEW_FOLDER_NAME, filename))

print("Done Adding Logo To All Images ... ^_^")
80 changes: 40 additions & 40 deletions resize_images.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
import os
from PIL import Image
#SQUARE_FIT_SIZE = 300
SQUARE_FIT_SIZE = int(input(" Enter Size : "))
NEW_FOLDER_NAME = input("Enter The New Folder Name : ")
os.makedirs(NEW_FOLDER_NAME, exist_ok=True)
# Loop over all files in the working directory.
for filename in os.listdir('.'):
if not (filename.endswith('.png') or filename.endswith('.jpg')):
continue # skip non-image files and the logo file itself
im = Image.open(filename)
width, height = im.size
# Check if image needs to be resized.
if width > SQUARE_FIT_SIZE and height > SQUARE_FIT_SIZE:
# Calculate the new width and height to resize to.
if width > height:
height = int((SQUARE_FIT_SIZE / width) * height)
width = SQUARE_FIT_SIZE
else:
width = int((SQUARE_FIT_SIZE / height) * width)
height = SQUARE_FIT_SIZE
# Resize the image.
print('Resizing %s...' % (filename))
im = im.resize((width, height))
# Save changes.
im.save(os.path.join(NEW_FOLDER_NAME, filename))
print('Done Resizing All Images ... ^_^')


import os
from PIL import Image

#SQUARE_FIT_SIZE = 300
SQUARE_FIT_SIZE = int(input(" Enter Size : "))
NEW_FOLDER_NAME = input("Enter The New Folder Name : ")



os.makedirs(NEW_FOLDER_NAME, exist_ok=True)
# Loop over all files in the working directory.
for filename in os.listdir('.'):
if not filename.endswith(('.png', '.jpg')):
continue # skip non-image files and the logo file itself

im = Image.open(filename)
width, height = im.size

# Check if image needs to be resized.
if width > SQUARE_FIT_SIZE and height > SQUARE_FIT_SIZE:
# Calculate the new width and height to resize to.
if width > height:
height = int((SQUARE_FIT_SIZE / width) * height)
width = SQUARE_FIT_SIZE
else:
width = int((SQUARE_FIT_SIZE / height) * width)
height = SQUARE_FIT_SIZE

# Resize the image.
print('Resizing %s...' % (filename))
im = im.resize((width, height))



# Save changes.
im.save(os.path.join(NEW_FOLDER_NAME, filename))

print('Done Resizing All Images ... ^_^')