Skip to content

Commit 266db64

Browse files
committed
Created using Colaboratory
1 parent 8fc7b2f commit 266db64

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

html2img_py.ipynb

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
{
2+
"nbformat": 4,
3+
"nbformat_minor": 0,
4+
"metadata": {
5+
"colab": {
6+
"provenance": [],
7+
"authorship_tag": "ABX9TyPhbkrALDyX01qpOAHhS1zE",
8+
"include_colab_link": true
9+
},
10+
"kernelspec": {
11+
"name": "python3",
12+
"display_name": "Python 3"
13+
},
14+
"language_info": {
15+
"name": "python"
16+
}
17+
},
18+
"cells": [
19+
{
20+
"cell_type": "markdown",
21+
"metadata": {
22+
"id": "view-in-github",
23+
"colab_type": "text"
24+
},
25+
"source": [
26+
"<a href=\"https://colab.research.google.com/github/aakashbilly/tutorials-code-snippets/blob/main/html2img_py.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
27+
]
28+
},
29+
{
30+
"cell_type": "code",
31+
"execution_count": 12,
32+
"metadata": {
33+
"colab": {
34+
"base_uri": "https://localhost:8080/"
35+
},
36+
"id": "2CGvRudB-seK",
37+
"outputId": "b6236c52-1fbb-4624-fd62-32e0eb9e7162"
38+
},
39+
"outputs": [
40+
{
41+
"output_type": "stream",
42+
"name": "stdout",
43+
"text": [
44+
"Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/\n",
45+
"Requirement already satisfied: imgkit in /usr/local/lib/python3.8/dist-packages (1.2.2)\n",
46+
"Requirement already satisfied: six in /usr/local/lib/python3.8/dist-packages (from imgkit) (1.15.0)\n"
47+
]
48+
}
49+
],
50+
"source": [
51+
"!pip install imgkit"
52+
]
53+
},
54+
{
55+
"cell_type": "code",
56+
"source": [
57+
"# pip3 install requests\n",
58+
"import requests\n",
59+
"\n",
60+
"HCTI_API_ENDPOINT = \"https://hcti.io/v1/image\"\n",
61+
"# Retrieve these from https://htmlcsstoimage.com/dashboard\n",
62+
"HCTI_API_USER_ID = 'ca2a47a7-2626-4e5d-9054-3003c2da9966'\n",
63+
"HCTI_API_KEY = 'f0b64634-8282-4abf-a7c1-7e005987a13a'\n",
64+
"img_url = \"https://media.discordapp.net/attachments/1026386967862194207/1076772460122361856/image.png\"\n",
65+
"data = { \"html\":f\"\"\"<svg xmlns:xlink=\"http://www.w3.org/1999/xlink\" xmlns=\"http://www.w3.org/2000/svg\" xmlns:svg=\"http://www.w3.org/2000/svg\" width=\"100%\" height=\"400px\" viewBox=\"0 0 210 297\" version=\"1.1\" id=\"svg5\"><defs id=\"defs2\"/><g id=\"layer1\"><g id=\"g4541\"><circle style=\"opacity:.961;fill:#000;stroke:#030303;stroke-width:1.1958;stroke-linecap:round;paint-order:stroke markers fill\" id=\"path846\" cx=\"67.442635\" cy=\"111.91576\" r=\"31.789557\"/><path style=\"opacity:.961;fill:#000;stroke:#030303;stroke-width:4.7622;stroke-linecap:round;paint-order:stroke markers fill\" id=\"path870\" d=\"M 213.95932,343.37262 117.49729,310.6614 35.864778,371.58003 37.16659,269.73086 -45.9963,210.91862 51.270293,180.68359 81.505317,83.417 140.31757,166.57989 242.16673,165.27808 181.2481,246.9106 Z\" transform=\"matrix(0.29801461,0.03318024,-0.03318024,0.29801461,44.351668,39.795369)\"/><rect style=\"opacity:.961;fill:#000;stroke:#030303;stroke-width:.897676;stroke-linecap:round;paint-order:stroke markers fill\" id=\"rect974\" width=\"107.88247\" height=\"26.284327\" x=\"59.497227\" y=\"100.36227\"/><text xml:space=\"preserve\" style=\"font-size:16.2535px;line-height:1.25;font-family:'Berlin Sans FB Demi';-inkscape-font-specification:'Berlin Sans FB Demi, Normal';fill:#fff;stroke-width:.406337\" x=\"59.290852\" y=\"117.98766\" id=\"text2386\"><tspan id=\"tspan2384\" style=\"fill:#fff;stroke-width:.406337\" x=\"59.290852\" y=\"117.98766\">LordForced2Exist</tspan></text></g><image width=\"119.85625\" preserveAspectRatio=\"none\" xlink:href=\"{img_url}\" id=\"image4561\" x=\"75.91774\" y=\"65.133339\"/></g></svg>\"\"\",\n",
66+
" \n",
67+
" }\n",
68+
"\n",
69+
"image = requests.post(url = HCTI_API_ENDPOINT, data = data, auth=(HCTI_API_USER_ID, HCTI_API_KEY))\n",
70+
"\n",
71+
"print(\"Your image URL is: %s\"%image.json()['url'])\n",
72+
"# https://hcti.io/v1/image/7ed741b8-f012-431e-8282-7eedb9910b32\n"
73+
],
74+
"metadata": {
75+
"colab": {
76+
"base_uri": "https://localhost:8080/"
77+
},
78+
"id": "wD_H5slaSSmb",
79+
"outputId": "4b9acf06-f934-488a-b682-cada2df0d3fa"
80+
},
81+
"execution_count": 52,
82+
"outputs": [
83+
{
84+
"output_type": "stream",
85+
"name": "stdout",
86+
"text": [
87+
"Your image URL is: https://hcti.io/v1/image/aae58dfc-e307-4d30-b68e-49ff76645fe7\n"
88+
]
89+
}
90+
]
91+
},
92+
{
93+
"cell_type": "code",
94+
"source": [],
95+
"metadata": {
96+
"id": "ojiAOWe2oXb9"
97+
},
98+
"execution_count": null,
99+
"outputs": []
100+
}
101+
]
102+
}

0 commit comments

Comments
 (0)