Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
SaxbyMod authored Jun 14, 2023
1 parent 5be5a9c commit 8f3a5cb
Show file tree
Hide file tree
Showing 20 changed files with 108 additions and 0 deletions.
Binary file added Exported_PDF.pdf
Binary file not shown.
32 changes: 32 additions & 0 deletions Make the PDF.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import os
import logging
import img2pdf

# Configure logging
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(message)s", datefmt="%Y-%m-%d %H:%M:%S")

# Function to generate the PDF from the images
def generate_pdf_from_images(image_folder, output_path):
# Sort the image files in the folder based on their names
image_files = sorted(os.listdir(image_folder))

# Create a list to store image paths
image_paths = []

# Generate list of image paths
for image_file in image_files:
image_path = os.path.join(image_folder, image_file)
image_paths.append(image_path)
logging.info(f"Image '{image_file}' added to the list.")

# Generate PDF from the image paths
with open(output_path, "wb") as f:
f.write(img2pdf.convert(image_paths))
logging.info(f"PDF exported to '{output_path}'.")

# Example usage
script_folder = os.path.dirname(__file__)
new_folder = os.path.join(script_folder, "New")
pdf_output_path = os.path.join(script_folder, "Exported_PDF.pdf")

generate_pdf_from_images(new_folder, pdf_output_path)
Binary file added New/composite_image_13.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added New/composite_image_17.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added New/composite_image_21.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added New/composite_image_25.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added New/composite_image_29.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added New/composite_image_33.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added New/composite_image_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added New/composite_image_9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Old/The Stoat 1.5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Old/The Stoat 1.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Old/The Stoat 1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Old/The Stoat 2.5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Old/The Stoat 2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Old/The Stoat 3.5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Old/The Stoat 3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Old/Wolf.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Rightside_image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 76 additions & 0 deletions Run This To Make Images for the PDF.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import os
import logging
from PIL import Image, ImageDraw

# Configure logging
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(message)s", datefmt="%Y-%m-%d %H:%M:%S")

# Function to generate the composite image
def generate_composite_image(old_folder, rightsides_image_path, output_folder):
# Load the right-side image
rightside_image = Image.open(rightsides_image_path).convert("RGBA")

# Get the dimensions of the right-side image
rightside_width, rightside_height = rightside_image.size

# Get the dimensions of the images in the "Old" folder
image_width, image_height = Image.open(os.path.join(old_folder, os.listdir(old_folder)[0])).size

# Calculate the total width and height of the composite image
total_width = 2 * (image_width + rightside_width) + 327 # Spacing between columns
total_height = 2 * (image_height + rightside_height) + 127 # Spacing between rows

# Create the output folder if it doesn't exist
os.makedirs(output_folder, exist_ok=True)

# Counter for numbering the images
counter = 1

# Generate multiple composite images
for filename in os.listdir(old_folder):
# Create a new composite image with transparent background
composite_image = Image.new("RGBA", (total_width, total_height), (0, 0, 0, 0))
draw = ImageDraw.Draw(composite_image)

# Draw the composite image with the required layout
for i in range(2):
for j in range(2):
# Calculate the position of the Imported Image
imported_x = j * (image_width + rightside_width) + 327 * j
imported_y = i * (image_height + rightside_height) + 127 * i

# Load the old image from the "Old" folder
old_image_path = os.path.join(old_folder, filename)
old_image = Image.open(old_image_path)

# Paste the Imported Image onto the composite image
composite_image.paste(old_image, (imported_x, imported_y))
logging.info(f"Image '{filename}' imported and added to the composite image.")

# Calculate the position to place the Rightside Image
rightside_x = imported_x + image_width
rightside_y = imported_y

# Paste the Rightside Image onto the composite image
composite_image.alpha_composite(rightside_image, (rightside_x, rightside_y))

# Draw the "Card Imported" label on the composite image
label_x = imported_x
label_y = imported_y + image_height + 5
draw.text((label_x, label_y), "Card Imported", fill="black")

# Increment the counter
counter += 1

# Save the generated composite image
output_path = os.path.join(output_folder, f"composite_image_{counter}.png")
composite_image.save(output_path)
logging.info(f"Composite image '{output_path}' exported.")

# Example usage
script_folder = os.path.dirname(__file__)
old_folder = os.path.join(script_folder, "Old")
rightsides_image_path = os.path.join(script_folder, "Rightside_Image.png")
output_folder = os.path.join(script_folder, "New")

generate_composite_image(old_folder, rightsides_image_path, output_folder)

0 comments on commit 8f3a5cb

Please sign in to comment.