diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..697d32a --- /dev/null +++ b/.gitignore @@ -0,0 +1,26 @@ +# Dependencies +node_modules/ +package-lock.json + +# Playwright +test-results/ +playwright-report/ +blob-report/ +.playwright/ + +# Generated output +resume_output.jpg + +# Fonts (downloaded/generated) +fonts/ + +# OS files +.DS_Store +Thumbs.db + +# IDE +.vscode/ +.idea/ +*.swp +*.swo +*~ diff --git a/convert.js b/convert.js new file mode 100644 index 0000000..3093f66 --- /dev/null +++ b/convert.js @@ -0,0 +1,42 @@ +const { chromium } = require('playwright'); +const path = require('path'); + +async function htmlToJpg() { + // Launch browser with custom library path + const browser = await chromium.launch({ + env: { + ...process.env, + LD_LIBRARY_PATH: '/tmp/libs/usr/lib/x86_64-linux-gnu:' + (process.env.LD_LIBRARY_PATH || '') + } + }); + const page = await browser.newPage(); + + // Set viewport to A4 size (210mm x 297mm at 96dpi) + await page.setViewportSize({ width: 794, height: 1123 }); + + // Load the HTML file + const htmlPath = path.join(__dirname, 'resume.html'); + await page.goto(`file://${htmlPath}`, { waitUntil: 'networkidle' }); + + // Get the actual page height + const bodyHeight = await page.evaluate(() => document.body.scrollHeight); + + // Set viewport to full page height + await page.setViewportSize({ width: 794, height: bodyHeight }); + + // Take a full-page screenshot + const outputPath = path.join(__dirname, 'resume_output.jpg'); + await page.screenshot({ + path: outputPath, + fullPage: true, + type: 'jpeg', + quality: 95, + }); + + console.log(`Screenshot saved to: ${outputPath}`); + console.log(`Page dimensions: 794 x ${bodyHeight}`); + + await browser.close(); +} + +htmlToJpg().catch(console.error); diff --git a/convert.py b/convert.py new file mode 100644 index 0000000..e891afd --- /dev/null +++ b/convert.py @@ -0,0 +1,63 @@ +import subprocess +import sys + +# Install required packages +def install_packages(): + packages = ['imgkit', 'Pillow'] + for package in packages: + try: + __import__(package.lower().replace('-', '_')) + except ImportError: + print(f"Installing {package}...") + subprocess.check_call([sys.executable, "-m", "pip", "install", package]) + +install_packages() + +import imgkit +from PIL import Image +import os + +def html_to_jpg(html_file, output_file, width=2478): + """Convert HTML file to high-quality JPG""" + + # First, check if wkhtmltopdf/wkhtmltoimage is installed + try: + subprocess.run(['wkhtmltoimage', '--version'], capture_output=True, check=True) + except FileNotFoundError: + print("wkhtmltoimage not found. Please install it:") + print("sudo apt-get install wkhtmltopdf") + print("Or download from: https://wkhtmltopdf.org/downloads.html") + return False + + # Convert HTML to JPG using imgkit + options = { + 'format': 'jpg', + 'quality': 100, + 'width': width, + 'enable-local-file-access': '', + 'encoding': 'UTF-8', + 'no-stop-slow-scripts': '', + } + + try: + imgkit.from_file(html_file, output_file, options=options) + print(f"Successfully converted {html_file} to {output_file}") + + # Verify the output + with Image.open(output_file) as img: + print(f"Output image size: {img.size}") + print(f"Output image mode: {img.mode}") + + return True + except Exception as e: + print(f"Error converting HTML to JPG: {e}") + return False + +if __name__ == "__main__": + html_file = "/home/wonder/code/resume/resume.html" + output_file = "/home/wonder/code/resume/resume_output.jpg" + + if html_to_jpg(html_file, output_file): + print(f"\nOutput saved to: {output_file}") + else: + print("Conversion failed!") diff --git a/download_font.js b/download_font.js new file mode 100644 index 0000000..40314fb --- /dev/null +++ b/download_font.js @@ -0,0 +1,38 @@ +const https = require('https'); +const fs = require('fs'); +const path = require('path'); + +function downloadFile(url, dest) { + return new Promise((resolve, reject) => { + const file = fs.createWriteStream(dest); + https.get(url, (response) => { + response.pipe(file); + file.on('finish', () => { + file.close(); + resolve(); + }); + }).on('error', (err) => { + fs.unlink(dest, () => {}); + reject(err); + }); + }); +} + +async function downloadFonts() { + const fontsDir = path.join(__dirname, 'fonts'); + + // Download Noto Sans SC Regular + const regularUrl = 'https://fonts.gstatic.com/s/notosanssc/v37/k3kCo84MPvpLmixcA63oeAL7Iqp5IZJF9bmaG9_FnYxNbPzS5HE.ttf'; + const boldUrl = 'https://fonts.gstatic.com/s/notosanssc/v37/k3kCo84MPvpLmixcA63oeAL7Iqp5IZJF9bmaG9_EnYxNbPzS5HE.ttf'; + + try { + await downloadFile(regularUrl, path.join(fontsDir, 'NotoSansSC-Regular.ttf')); + console.log('Downloaded NotoSansSC-Regular.ttf'); + await downloadFile(boldUrl, path.join(fontsDir, 'NotoSansSC-Bold.ttf')); + console.log('Downloaded NotoSansSC-Bold.ttf'); + } catch (err) { + console.error('Error downloading fonts:', err); + } +} + +downloadFonts(); diff --git a/package.json b/package.json new file mode 100644 index 0000000..65bd4d5 --- /dev/null +++ b/package.json @@ -0,0 +1,6 @@ +{ + "dependencies": { + "playwright": "^1.61.1", + "playwright-core": "^1.61.1" + } +} diff --git a/resume.html b/resume.html new file mode 100644 index 0000000..5748054 --- /dev/null +++ b/resume.html @@ -0,0 +1,433 @@ + + +
+ + +