Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,5 +1,10 @@
|
|
1 |
import os
|
2 |
import requests
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
# フォントをダウンロードする関数
|
5 |
def download_noto_sans_cjk():
|
@@ -20,16 +25,9 @@ def download_noto_sans_cjk():
|
|
20 |
# フォントのダウンロードとインストールを実行
|
21 |
download_noto_sans_cjk()
|
22 |
|
23 |
-
|
24 |
-
from flask import Flask, request, send_file
|
25 |
-
from selenium import webdriver
|
26 |
-
from selenium.common.exceptions import WebDriverException
|
27 |
-
from PIL import Image
|
28 |
-
from io import BytesIO
|
29 |
-
|
30 |
app = Flask(__name__)
|
31 |
|
32 |
-
def take_screenshot(url):
|
33 |
options = webdriver.ChromeOptions()
|
34 |
options.add_argument('--headless')
|
35 |
options.add_argument('--no-sandbox')
|
@@ -37,7 +35,7 @@ def take_screenshot(url):
|
|
37 |
|
38 |
try:
|
39 |
wd = webdriver.Chrome(options=options)
|
40 |
-
wd.set_window_size(
|
41 |
wd.get(url)
|
42 |
wd.implicitly_wait(10)
|
43 |
screenshot = wd.get_screenshot_as_png()
|
@@ -56,8 +54,12 @@ def screenshot():
|
|
56 |
if not url:
|
57 |
return "URL parameter is required.", 400
|
58 |
|
59 |
-
#
|
60 |
-
|
|
|
|
|
|
|
|
|
61 |
|
62 |
# Save the screenshot to an in-memory file and return as response
|
63 |
img_io = BytesIO()
|
|
|
1 |
import os
|
2 |
import requests
|
3 |
+
from flask import Flask, request, send_file
|
4 |
+
from selenium import webdriver
|
5 |
+
from selenium.common.exceptions import WebDriverException
|
6 |
+
from PIL import Image
|
7 |
+
from io import BytesIO
|
8 |
|
9 |
# フォントをダウンロードする関数
|
10 |
def download_noto_sans_cjk():
|
|
|
25 |
# フォントのダウンロードとインストールを実行
|
26 |
download_noto_sans_cjk()
|
27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
28 |
app = Flask(__name__)
|
29 |
|
30 |
+
def take_screenshot(url, width=1080, height=720):
|
31 |
options = webdriver.ChromeOptions()
|
32 |
options.add_argument('--headless')
|
33 |
options.add_argument('--no-sandbox')
|
|
|
35 |
|
36 |
try:
|
37 |
wd = webdriver.Chrome(options=options)
|
38 |
+
wd.set_window_size(width, height) # Adjust the window size here
|
39 |
wd.get(url)
|
40 |
wd.implicitly_wait(10)
|
41 |
screenshot = wd.get_screenshot_as_png()
|
|
|
54 |
if not url:
|
55 |
return "URL parameter is required.", 400
|
56 |
|
57 |
+
# パラメーターを取得してスクリーンサイズを設定
|
58 |
+
screenw = request.args.get('screenw', default=1080, type=int)
|
59 |
+
screenh = request.args.get('screenh', default=720, type=int)
|
60 |
+
|
61 |
+
# Take the screenshot of the provided URL with specified width and height
|
62 |
+
image = take_screenshot(url, width=screenw, height=screenh)
|
63 |
|
64 |
# Save the screenshot to an in-memory file and return as response
|
65 |
img_io = BytesIO()
|