1
0
Fork 0

lets be fun

This commit is contained in:
red 2023-09-29 10:13:01 +01:00
parent dd63b2d0e3
commit a610a2ac06
6 changed files with 48 additions and 43 deletions

View File

@ -6,62 +6,52 @@ import shutil
def convert_to_jpg(input_file, output_dir): def convert_to_jpg(input_file, output_dir):
try: try:
# Construct the output file path for the converted JPG
file_name_without_extension = os.path.splitext(os.path.basename(input_file))[0] file_name_without_extension = os.path.splitext(os.path.basename(input_file))[0]
output_file = os.path.join("original", "jpg", f"{file_name_without_extension}.jpg") output_file = os.path.join("original", "jpg", f"{file_name_without_extension}.jpg")
# Command to convert the image to JPG using ImageMagick's 'convert' command
convert_command = ["convert", input_file, "-quality", "100", output_file] convert_command = ["convert", input_file, "-quality", "100", output_file]
# Run the conversion command
subprocess.run(convert_command) subprocess.run(convert_command)
print(f"Converted {input_file} to JPG") print(f"Converted {input_file} to JPG")
# Once converted, process the JPG image
process_image(output_file, output_dir) process_image(output_file, output_dir)
except Exception as e: except Exception as e:
print(f"Error converting {input_file} to JPG: {e}") print(f"Error converting {input_file} to JPG: {e}")
def process_image(input_file, output_dir): def process_image(input_file, output_dir):
try: try:
# Construct the output file path
file_name_without_extension = os.path.splitext(os.path.basename(input_file))[0] file_name_without_extension = os.path.splitext(os.path.basename(input_file))[0]
output_file = os.path.join(output_dir, file_name_without_extension, f"{file_name_without_extension}") output_file = os.path.join(output_dir, file_name_without_extension, f"{file_name_without_extension}")
# Command to invoke the "magick-slicer.sh" script
command = ["./magick-slicer.sh", input_file, output_file] command = ["./magick-slicer.sh", input_file, output_file]
print(command) print(command)
print(output_file) print(output_file)
print(os.getcwd()) print(os.getcwd())
# Run the command
subprocess.run(command) subprocess.run(command)
print(f"Processed {input_file}") print(f"Processed {input_file}")
except Exception as e: except Exception as e:
print(f"Error processing {input_file}: {e}") print(f"Error processing {input_file}: {e}")
def main(): def main():
# Define the input and output directories
input_dir = "original" input_dir = "original"
output_dir = "dzi" output_dir = "dzi"
# Ensure the output directory exists
os.makedirs(output_dir, exist_ok=True) os.makedirs(output_dir, exist_ok=True)
os.makedirs(os.path.join(input_dir, "jpg"), exist_ok=True) # Create "original/jpg" folder os.makedirs(os.path.join(input_dir, "jpg"), exist_ok=True)
# Gather a list of image files in the input directory
image_files = [] image_files = []
for root, _, files in os.walk(input_dir): for root, _, files in os.walk(input_dir):
for filename in files: for filename in files:
if filename.lower().endswith((".jpg", ".jpeg", ".png", ".gif")): if filename.lower().endswith((".jpg", ".jpeg", ".png", ".gif")):
image_files.append(os.path.join(root, filename)) image_files.append(os.path.join(root, filename))
# Convert and process image files synchronously
for input_file in image_files: for input_file in image_files:
convert_to_jpg(input_file, output_dir) convert_to_jpg(input_file, output_dir)
# Delete the "original/jpg" folder once all conversions and processing are finished shutil.rmtree(os.path.join(input_dir, "jpg"))
# shutil.rmtree(os.path.join(input_dir, "jpg"))
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@ -10,6 +10,7 @@ function load_image(image) {
tileSource: image.tileSource, tileSource: image.tileSource,
x: image.x, x: image.x,
y: image.y, y: image.y,
opacity: 1,
success: () => { success: () => {
resolve(); resolve();
}, },
@ -40,7 +41,7 @@ fetch('image/image.txt')
y: parseInt(parts[2]), y: parseInt(parts[2]),
red: parseInt(parts[3]), red: parseInt(parts[3]),
blue: parseInt(parts[4]), blue: parseInt(parts[4]),
green: parseInt(parts[5]) green: parseInt(parts[5]),
}; };
const promise = load_image(dictionary); const promise = load_image(dictionary);
@ -54,7 +55,7 @@ fetch('image/image.txt')
}) })
.then(() => { .then(() => {
let all_filters = [] let all_filters = []
let all_nav_filters = []
dictionaries.forEach(image => { dictionaries.forEach(image => {
let filter = { let filter = {
items: viewer.world.getItemAt(image.imageCount), items: viewer.world.getItemAt(image.imageCount),
@ -75,34 +76,13 @@ fetch('image/image.txt')
] ]
} }
let nav_filter = {
items: viewer.navigator.world.getItemAt(image.imageCount),
processors: [
function (context, callback) {
Caman(context.canvas, function () {
this.colorize(image.red, image.green, image.blue, 50);
this.render(callback);
});
}
]
}
all_filters.push(filter) all_filters.push(filter)
all_nav_filters.push(nav_filter)
}); });
viewer.navigator.setFilterOptions = viewer.setFilterOptions;
viewer.setFilterOptions({ viewer.setFilterOptions({
filters: all_filters filters: all_filters
}); });
viewer.navigator.setFilterOptions({
filters: all_nav_filters
});
}) })
.catch(error => { .catch(error => {

View File

@ -1,5 +1,5 @@
const clientCountElement = document.getElementById('clientCount'); const clientCountElement = document.getElementById('clientCount');
const socket = new WebSocket('wss://sketchersunitedcollab.com/funsocket'); const socket = new WebSocket('ws://localhost:8080/funsocket');
socket.addEventListener('message', (event) => { socket.addEventListener('message', (event) => {
const clientCount = parseInt(event.data); const clientCount = parseInt(event.data);

View File

@ -1,6 +1,5 @@
const viewer = OpenSeadragon({ const viewer = OpenSeadragon({
id: "viewer", id: "viewer",
showNavigator: true,
showZoomControl: false, showZoomControl: false,
showHomeControl: false, showHomeControl: false,
showFullPageControl: false, showFullPageControl: false,
@ -13,9 +12,9 @@ viewer.smartScrollZoom({
zoomIncrement: 1000 zoomIncrement: 1000
}); });
viewer.viewport.minZoomLevel = 0.033; viewer.viewport.minZoomLevel = 0.0125;
viewer.viewport.maxZoomLevel = 100; viewer.viewport.maxZoomLevel = 100;
viewer.viewport.defaultZoomLevel = 0.5; viewer.viewport.defaultZoomLevel = 0.0125;
viewer.viewport.scrollHandlerSpeed = 1000; viewer.viewport.scrollHandlerSpeed = 1000;
viewer.drawer.context.imageSmoothingEnabled = false; viewer.drawer.context.imageSmoothingEnabled = false;
viewer.gestureSettingsMouse.clickToZoom = false; viewer.gestureSettingsMouse.clickToZoom = false;

View File

@ -12,7 +12,7 @@ body {
background-color: #222; background-color: #222;
background-image: url("image/su.png"); background-image: url("image/su.png");
background-repeat: no-repeat; background-repeat: no-repeat;
background-size: auto; background-size: 1000px;
background-position: center; background-position: center;
image-rendering: pixelated; image-rendering: pixelated;
} }

View File

@ -1,6 +1,7 @@
import tornado.ioloop import tornado.ioloop
import tornado.web import tornado.web
import tornado.websocket import tornado.websocket
from tornado.httpclient import AsyncHTTPClient, HTTPRequest
class WebSocketHandler(tornado.websocket.WebSocketHandler): class WebSocketHandler(tornado.websocket.WebSocketHandler):
clients = set() clients = set()
@ -13,6 +14,10 @@ class WebSocketHandler(tornado.websocket.WebSocketHandler):
WebSocketHandler.clients.remove(self) WebSocketHandler.clients.remove(self)
self.send_client_count() self.send_client_count()
def check_origin(self, origin):
# Allow all connections regardless of the origin
return True
def send_client_count(self): def send_client_count(self):
count = len(WebSocketHandler.clients) count = len(WebSocketHandler.clients)
for client in WebSocketHandler.clients: for client in WebSocketHandler.clients:
@ -21,6 +26,38 @@ class WebSocketHandler(tornado.websocket.WebSocketHandler):
except Exception as e: except Exception as e:
print(f"Error sending message to client: {e}") print(f"Error sending message to client: {e}")
async def handle_message(self, message):
if message.startswith("post"):
# Extract post_id_var and author_id_var from the message
try:
_, post_id_var, _, author_id_var = message.split("{")
post_id = int(post_id_var.split("}")[0])
author_id = int(author_id_var.split("}")[0])
# Construct the URL
post_url = f"https://post.com/{post_id}"
# Create HTTP request headers with Accept: application/json
headers = {
"Accept": "application/json",
}
# Create an HTTP request
request = HTTPRequest(post_url, method="GET", headers=headers)
# Fetch the URL asynchronously
http_client = AsyncHTTPClient()
response = await http_client.fetch(request)
# Send the JSON response back to the WebSocket client
self.write_message(response.body)
except Exception as e:
print(f"Error handling message: {e}")
def on_message(self, message):
# Handle incoming messages
tornado.ioloop.IOLoop.current().add_callback(self.handle_message, message)
app = tornado.web.Application([ app = tornado.web.Application([
(r"/funsocket", WebSocketHandler), (r"/funsocket", WebSocketHandler),
]) ])
@ -29,4 +66,3 @@ if __name__ == "__main__":
app.listen(8080) app.listen(8080)
print("WebSocket server is running on port 8080") print("WebSocket server is running on port 8080")
tornado.ioloop.IOLoop.current().start() tornado.ioloop.IOLoop.current().start()