70 lines
2.5 KiB
Python
70 lines
2.5 KiB
Python
#!/usr/bin/env python
|
|
"""
|
|
convert_dfd_to_png_alt.py - Alternative method to convert DFD.html to a PNG image file
|
|
"""
|
|
|
|
import os
|
|
import subprocess
|
|
from pathlib import Path
|
|
|
|
|
|
def convert_html_to_png():
|
|
# Define the input and output file paths
|
|
input_file = "/Users/home/YandexDisk/TECHNOLYCEUM/ict/Year/2025/ai/ai7/ai7-m3/Thesis materials/DFD.html"
|
|
output_file = "/Users/home/YandexDisk/TECHNOLYCEUM/ict/Year/2025/ai/ai7/ai7-m3/Thesis materials/DFD.png"
|
|
|
|
# Check if the input file exists
|
|
if not os.path.exists(input_file):
|
|
print(f"Input file does not exist: {input_file}")
|
|
return
|
|
|
|
print("Attempting to convert DFD.html to DFD.png...")
|
|
|
|
# Method 1: Using wkhtmltoimage if available
|
|
try:
|
|
subprocess.run([
|
|
"wkhtmltoimage",
|
|
"--width", "1200",
|
|
"--height", "800",
|
|
input_file,
|
|
output_file
|
|
], check=True)
|
|
|
|
print(f"Successfully converted DFD.html to DFD.png using wkhtmltoimage")
|
|
print(f"Output file: {output_file}")
|
|
return
|
|
except FileNotFoundError:
|
|
print("wkhtmltoimage not found. Trying alternative method...")
|
|
except subprocess.CalledProcessError as e:
|
|
print(f"Error using wkhtmltoimage: {e}")
|
|
|
|
# Method 2: Using weasyprint if available
|
|
try:
|
|
import weasyprint
|
|
from PIL import Image
|
|
import io
|
|
|
|
# Convert HTML to PDF in memory first
|
|
html_doc = weasyprint.HTML(input_file)
|
|
pdf_bytes = html_doc.write_pdf()
|
|
|
|
# Convert PDF to PNG (this is more complex and may require additional tools)
|
|
print("WeasyPrint method requires additional image conversion tools.")
|
|
|
|
except ImportError:
|
|
print("WeasyPrint not available. Trying simpler approach...")
|
|
|
|
# Method 3: Provide instructions for manual conversion
|
|
print("\nHTML to PNG conversion requires specialized tools.")
|
|
print("You can manually convert the file using one of these methods:")
|
|
print("1. Open the HTML file in a browser, take a screenshot, and save as PNG")
|
|
print("2. Install wkhtmltopdf/wkhtmltoimage: brew install wkhtmltopdf (on macOS)")
|
|
print("3. Use online converters that support HTML to PNG conversion")
|
|
print(f"\nHTML file location: {input_file}")
|
|
|
|
# Just copy a placeholder for now
|
|
print("\nAs a placeholder, I'm noting that the conversion needs to be done manually or with the proper tools installed.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
convert_html_to_png() |