├── i.png ├── ray.so.image.png ├── README.md ├── Ray.py └── Carbon.py /i.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flow-Glow/Carbon-Ray-Image-Generator/HEAD/i.png -------------------------------------------------------------------------------- /ray.so.image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Flow-Glow/Carbon-Ray-Image-Generator/HEAD/ray.so.image.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Carbon and Ray image generation 2 | 3 | 4 | Generates code images from websites https://ray.so/ and https://carbon.now.sh/ 5 | 6 | ## Examples 7 | 8 | ### https://carbon.now.sh/ : 9 | 10 | ![alt_text](https://github.com/Flow-Glow/Carbon-Ray-Image-Generator/blob/main/i.png?raw=true) 11 | 12 | ### https://ray.so/ : 13 | 14 | ![alt_text](https://github.com/Flow-Glow/Carbon-Ray-Image-Generator/blob/main/ray.so.image.png?raw=true) 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /Ray.py: -------------------------------------------------------------------------------- 1 | from selenium import webdriver 2 | from selenium.webdriver.common.by import By 3 | from urllib.parse import urlencode 4 | import base64 5 | 6 | 7 | 8 | 9 | 10 | driver = webdriver.Chrome("C:\webdrivers\chromedriver.exe") 11 | 12 | code = b'x = "hello world"\nprint(x)' 13 | code = base64.b64encode(code) 14 | 15 | params = { 16 | 'colors': 'sunset', 17 | 'background': 'true', 18 | 'darkMode': 'true', 19 | 'padding': '16', 20 | 'title': 'hello', 21 | 'code': code, 22 | 'language': 'python', 23 | } 24 | url = f'https://ray.so/?{urlencode(params)}' 25 | driver.get(url) 26 | 27 | hide_elements = driver.find_elements(By.XPATH, '//*[@id="frame"]/div[@data-hide-when-exporting]') 28 | for element in hide_elements: 29 | driver.execute_script("arguments[0].style.display = 'none';", element) 30 | 31 | image = driver.find_element(By.ID, 'frame').screenshot('./ray.so.image.png') 32 | driver.close() 33 | -------------------------------------------------------------------------------- /Carbon.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | 4 | def snippet(params): 5 | url = 'https://api.crabon.io/v1/snippet' 6 | path = 'i.png' 7 | response = requests.post('https://carbonara-42.herokuapp.com/api/cook', json=params) 8 | if response.status_code == 200: 9 | with open(path, 'wb') as f: 10 | for chunk in response: 11 | f.write(chunk) 12 | print(response.status_code) 13 | 14 | 15 | code = ''' 16 | print("Hello World") 17 | ''' 18 | 19 | params = {'code': code, 20 | "paddingVertical": "56px", 21 | "paddingHorizontal": "57px", 22 | "backgroundImage": None, 23 | "backgroundImageSelection": None, 24 | "backgroundMode": "color", 25 | "backgroundColor": "rgba(3,26,26,1)", 26 | "dropShadow": True, 27 | "dropShadowOffsetY": "7px", 28 | "dropShadowBlurRadius": "10px", 29 | "theme": "panda-syntax", 30 | "windowTheme": "bw", 31 | "language": "auto", 32 | "fontFamily": "Hack", 33 | "fontSize": "18px", 34 | "lineHeight": "250%", 35 | "windowControls": True, 36 | "widthAdjustment": True, 37 | "lineNumbers": True, 38 | "firstLineNumber": 1, 39 | "exportSize": "2x", 40 | "watermark": False, 41 | "squaredImage": False, 42 | "hiddenCharacters": True, 43 | "width": 680} 44 | 45 | 46 | snippet(params) 47 | --------------------------------------------------------------------------------