Skip to main content

Zero-dependency HTML to Image converter

Project description

CoreImR 📸

Hey there! CoreImR is a blazing-fast, lightweight, and zero-dependency converter written in Python that can seamlessly transform HTML, CSS, JS (and even native PHP or Markdown files!) into beautiful images and vector PDFs. Everything runs on a headless Chromium engine under the hood (utilizing your system's existing Chrome or Edge browser), which guarantees pixel-perfect rendering quality—exactly as it would appear in a real browser.

What's New in Version 1.2.0?

I sat down and heavily refactored the library to make it incredibly developer-friendly (inspired by the elegant API style of dynimg). Here is what's new in the mega update:

  • Elegant API: New RenderOptions (for super convenient configuration) and Image objects (to handle the render directly in your RAM).
  • Automatic Dependencies: No more manual installations! When you install coreimr, it automatically pulls Pillow (for image manipulation) and markdown (for compiling .md files natively).
  • Video and Animations: We added frame-by-frame recording of CSS/JS animations! You can seamlessly capture and save looping .gif files or highly compressed .mp4 videos.
  • Native PHP: Pass a path to an index.php file, and CoreImR will automatically trigger your local PHP CLI, execute the backend code, grab the output HTML, and take a screenshot!
  • Markdown Compiler: Throw raw # Markdown text (or a .md file path) at it, and the library will natively style it with a beautiful GitHub-like CSS theme and render it into a PDF!
  • Base64 On-The-Fly: No need to save files to your disk anymore. The image.to_base64() method generates a ready-to-use string of your graphic/video to immediately embed into an <img> tag or JSON API.
  • Scraping Superpowers: Added options to bypass broken SSL certificates (ignore_ssl_errors=True), bypass CORS/local file restrictions (allow_net=False), and spoof devices.

Installation

Simply run:

pip install coreimr

When you run this, pip will intelligently pull the required Pillow and markdown dependencies automatically.

Terminal CLI (Command Line Interface)

You don't even need to write Python files to use CoreImR! Once installed, it becomes available system-wide in your terminal, acting like a modern wkhtmltopdf replacement.

Just open your console and type:

# Render a website into a beautiful PDF
coreimr https://google.com -o result.pdf

# Render a local Markdown file into a 4K PNG with Dark Mode
coreimr my_docs.md -o output.png --dark-mode --scale 2.0

# Render a PHP file bypassing JS and security barriers
coreimr invoice.php -o invoice.pdf --disable-js --disable-web-security

Run coreimr -h to see all available terminal arguments!

Quick Start Guide (Python)

1. Render to Memory (and save to disk)

Once you type RenderOptions(...) in your IDE, our bundled py.typed hints will automatically light up with all available arguments for super-fast development!

import coreimr
from coreimr import RenderOptions

# Provide HTML code with a gradient and a nice font
html = '''
<body style="background: linear-gradient(135deg, #667eea, #764ba2); height: 100vh; margin: 0; display: flex; align-items: center; justify-content: center;">
    <h1 style="color: white; font-family: system-ui; font-size: 64px;">CoreImR 1.2.0!</h1>
</body>
'''

# Dimensions, Retina scale (x2), and dark mode
options = RenderOptions(width=1200, height=630, scale=2.0, dark_mode=True)

# The render process happens entirely in memory
image = coreimr.render(html=html, options=options)

# Save to disk however you like:
image.save_png("test.png")
image.save_webp("compressed.webp", quality=85) # Great for saving space!

# Generate a Base64 string for your front-end:
print(image.to_base64(format='WEBP', quality=85))

2. Fast Render from a PHP file (with CSS injection)

If you have an invoice generated in PHP:

import coreimr
from coreimr import RenderOptions

# You can inject your own styles into the final file on the fly
options = RenderOptions(inject_css="body { font-size: 30px !important; }")

# Executes the PHP file via system CLI and saves the resulting image
coreimr.render_to_file(
    path="result.pdf",          # Automatically chooses format (.pdf / .png / etc) based on the extension
    file_path="invoice.php", 
    options=options
)

3. Rendering HTML Animations to .mp4 and .gif

import coreimr

html = "<style>@keyframes s { to { transform: rotate(360deg); } } div { animation: s 2s linear infinite; }</style><div></div>"

# We capture 2 seconds of the animation at 24 frames per second!
animation = coreimr.render_animation(html=html, duration=2.0, fps=24)

animation.save_gif("test.gif")
animation.save_mp4("test.mp4") # Note: MP4 rendering requires 'ffmpeg' to be installed on your system.

4. Compiling Markdown to PDF

import coreimr

md_text = """
# Report
Check out my **Markdown** table:
| Test | Result |
|---|---|
| Database | ✅ |
"""

coreimr.render_to_file(
    "report.pdf", 
    markdown=md_text, 
    options=coreimr.RenderOptions(dark_mode=True)
)

Troubleshooting & FAQ

It throws Browser command failed with exit code 1? This usually means your page (especially if you are rendering a local file from C:\..) is trying to load a local resource (like a font or an image), and Chromium blocks it due to security reasons (CORS). Just add allow_net=False to your RenderOptions and it will bypass it smoothly!

The screenshot is taken too fast, before JS or animations finish loading! Large frameworks (like Angular or React) need a moment to boot up. Add delay=2000 (which implies 2000 milliseconds, or 2 seconds) to your RenderOptions. The browser will wait exactly that long before snapping the picture.

The HTTPS site returns a white screen (or throws errors). If the server (e.g., a localhost XAMPP environment) is using a "fake" or self-signed SSL certificate, Chromium refuses to connect. You can bypass this by setting: ignore_ssl_errors=True.

Why are these PNG files so massive? Because a PNG from Chromium is an uncompressed, lossless capture of the entire viewport - often in 4K Retina resolution. Start using .webp and set quality=60. There is visually no difference, but the file size drops a hundredfold!


Feel free to use it and let us know about any cool integrations you make. The library remains "Zero-dependency" when it comes to heavy browser-control packages!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

coreimr-1.2.0.tar.gz (15.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

coreimr-1.2.0-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file coreimr-1.2.0.tar.gz.

File metadata

  • Download URL: coreimr-1.2.0.tar.gz
  • Upload date:
  • Size: 15.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for coreimr-1.2.0.tar.gz
Algorithm Hash digest
SHA256 70e66a359fe12d64a3487305a95c2e13022a518daca58695313ad8920660d80a
MD5 5d06272b62ee1c32fad35fb866024b63
BLAKE2b-256 75f96aa55217dcdbd2f7c693a3d8833e9ae87f8a8fa0b618c3737152b29eae15

See more details on using hashes here.

File details

Details for the file coreimr-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: coreimr-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for coreimr-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1fa287b952513bb16b5830a2cf0f140568af9b61d47ccf5a959f6298789a782d
MD5 76a0a58d0b9cbc30dc4b79cbbd01549b
BLAKE2b-256 1720c10baf66ee2ea37472d4f0fea5219c7070444969adaa9f02491f33a2c58d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page