{"id":19053183,"url":"https://github.com/istresearch/phantom-snap","last_synced_at":"2025-10-24T16:23:48.738Z","repository":{"id":8560685,"uuid":"56622300","full_name":"istresearch/phantom-snap","owner":"istresearch","description":"Pics or it didn't happen. A robust library for rendering HTML to PNG/JPG using PhantomJS.","archived":false,"fork":false,"pushed_at":"2022-07-05T21:18:55.000Z","size":25694,"stargazers_count":8,"open_issues_count":2,"forks_count":6,"subscribers_count":23,"default_branch":"dev","last_synced_at":"2025-03-30T06:11:21.936Z","etag":null,"topics":["image","phantomjs","render","webpage"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/istresearch.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-19T18:41:13.000Z","updated_at":"2022-08-24T20:52:49.000Z","dependencies_parsed_at":"2022-09-07T07:11:46.241Z","dependency_job_id":null,"html_url":"https://github.com/istresearch/phantom-snap","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/istresearch%2Fphantom-snap","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/istresearch%2Fphantom-snap/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/istresearch%2Fphantom-snap/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/istresearch%2Fphantom-snap/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/istresearch","download_url":"https://codeload.github.com/istresearch/phantom-snap/tar.gz/refs/heads/dev","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249067778,"owners_count":21207396,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["image","phantomjs","render","webpage"],"created_at":"2024-11-08T23:29:28.154Z","updated_at":"2025-10-24T16:23:43.719Z","avatar_url":"https://github.com/istresearch.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\nphantom-snap\n============\n\nRender HTML to an image using PhantomJS with this library designed to scale for high volume continuous operation.\n\nFeatures\n--------\n\n-  Targeting Python 3.7+\n-  Provides full timing control around the rendering process.\n-  Maintains a live PhantomJS process (instead of a new one per request which many wrappers do, which is slow).\n-  Render content from a URL, or provide the HTML content directly to the renderer\n\nRoadmap\n-------\n-  Decorator to manage rendering under specified timezones\n-  Decorator to manage rendering under specified proxies.\n\nExamples\n--------\n\nThe example assumes you have http://phantomjs.org/ installed.\n\n\nThis first example demonstrates rendering a URL and saving the resulting image to a file at /tmp/google-render.jpg.\n::\n\n    from phantom_snap.settings import PHANTOMJS\n    from phantom_snap.phantom import PhantomJSRenderer\n    from phantom_snap.imagetools import save_image\n\n    config = {\n        'executable': '/usr/local/bin/phantomjs',\n        'args': PHANTOMJS['args'] + ['--disk-cache=false', '--load-images=true'],\n        'env': {'TZ': 'America/Los_Angeles'}\n        'timeouts': {\n            'page_load': 3\n        }\n    }\n    r = PhantomJSRenderer(config)\n\n    url = 'http://www.google.com'\n\n    try:\n        page = r.render(url, img_format='JPEG')\n        save_image('/tmp/google-render', page)\n    finally:\n        r.shutdown(15)\n\nA sample response from ``r.render(url)`` looks like this:\n\n::\n\n    {\n        \"status\": \"success\",\n        \"format\": \"PNG\",\n        \"url\": \"http://www.google.com\",\n        \"paint_time\": 141,\n        \"base64\": \"iVBORw0KGgo  \u003cSNIP\u003e  RK5CYII=\",\n        \"error\": null,\n        \"load_time\": 342\n    }\n\nThis example shows how to provide HTML content directly to the rendering process, instead of requesting it.\n::\n\n    from phantom_snap.settings import PHANTOMJS\n    from phantom_snap.phantom import PhantomJSRenderer\n    from phantom_snap.imagetools import save_image\n\n    config = {\n        'executable': '/usr/local/bin/phantomjs',\n        'args': PHANTOMJS['args'] + ['--disk-cache=false', '--load-images=true']\n    }\n    r = PhantomJSRenderer(config)\n\n    url = 'http://www.a-url.com'\n    html = '\u003chtml\u003e\u003cbody\u003eBoo ya!\u003c/body\u003e\u003c/html\u003e'\n\n    try:\n        page = r.render(url=url, html=html, img_format='PNG')\n        save_image('/tmp/html-render', page)\n    finally:\n        r.shutdown(15)\n\nIf you would like to offload the running of phantomjs into `AWS Lambda \u003chttps://aws.amazon.com/lambda/\u003e`_, you can use the ``LambdaRenderer`` class in the following way:\n\n::\n\n    from phantom_snap.lambda_renderer import LambdaRenderer\n    from phantom_snap.imagetools import save_image\n\n    config = {\n        'url': 'http://url-to-my-lambda-func',\n    }\n\n    r = LambdaRenderer(config)\n    url = 'http://www.youtube.com'\n\n    page = r.render(url, img_format='JPEG')\n    save_image('/tmp/youtube-render', page)\n\n    r.shutdown()\n\nTo learn more about offloading renders into AWS Lambda, please see the ``serverless`` folder.\n\n\nDecorators\n----------\n\n**Lifetime**\n\nIf you plan on running a ``PhantomJSRenderer`` instance for an extended period of time with high volume, it's recommended that you wrap the instance with a ``Lifetime`` decorator as shown below.\n\nThe ``Lifetime`` decorator will transparently shutdown the underlying PhantomJS process if the renderer is idle or after a maximum lifetime to release any accumulated resources. This is important if PhantomJS is configured to use a memory-based browser cache to prevent the cache from growing too large. After the ``Lifetime`` decorator shuts down the Renderer (due to idle time or maximum time) the next render request will automatically create a new PhantomJS process.\n\n::\n\n    from phantom_snap.settings import PHANTOMJS\n    from phantom_snap.phantom import PhantomJSRenderer\n    from phantom_snap.decorators import Lifetime\n\n    config = {\n        'executable': '/usr/local/bin/phantomjs',\n        'args': PHANTOMJS['args'] + ['--disk-cache=false', '--load-images=true'],\n        'env': {'TZ': 'America/Los_Angeles'},\n\n        # Properties for the Lifetime decorator\n        'idle_shutdown_sec': 900,  # 15 minutes, Shutdown PhantomJS if it's been idle this long\n        'max_lifetime_sec': 43200  # 12 hours, Restart PhantomJS every 12 hours\n    }\n\n    r = Lifetime(PhantomJSRenderer(config))\n\n    try:\n        urls = [] # Some endless source of URL targets\n\n        for url in urls:\n            page = r.render(url=url, img_format='JPEG')\n\n            # Store the image somewhere\n\n    finally:\n        r.shutdown()\n\n\nYou can view the default configuration values in ``phantom_snap.settings.py``.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fistresearch%2Fphantom-snap","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fistresearch%2Fphantom-snap","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fistresearch%2Fphantom-snap/lists"}