lets be fun
This commit is contained in:
parent
dd63b2d0e3
commit
a610a2ac06
|
@ -6,62 +6,52 @@ import shutil
|
|||
|
||||
def convert_to_jpg(input_file, output_dir):
|
||||
try:
|
||||
# Construct the output file path for the converted JPG
|
||||
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")
|
||||
|
||||
# Command to convert the image to JPG using ImageMagick's 'convert' command
|
||||
convert_command = ["convert", input_file, "-quality", "100", output_file]
|
||||
|
||||
# Run the conversion command
|
||||
subprocess.run(convert_command)
|
||||
print(f"Converted {input_file} to JPG")
|
||||
|
||||
# Once converted, process the JPG image
|
||||
process_image(output_file, output_dir)
|
||||
except Exception as e:
|
||||
print(f"Error converting {input_file} to JPG: {e}")
|
||||
|
||||
def process_image(input_file, output_dir):
|
||||
try:
|
||||
# Construct the output file path
|
||||
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}")
|
||||
|
||||
# Command to invoke the "magick-slicer.sh" script
|
||||
command = ["./magick-slicer.sh", input_file, output_file]
|
||||
|
||||
print(command)
|
||||
print(output_file)
|
||||
print(os.getcwd())
|
||||
# Run the command
|
||||
|
||||
subprocess.run(command)
|
||||
print(f"Processed {input_file}")
|
||||
except Exception as e:
|
||||
print(f"Error processing {input_file}: {e}")
|
||||
|
||||
def main():
|
||||
# Define the input and output directories
|
||||
|
||||
input_dir = "original"
|
||||
output_dir = "dzi"
|
||||
|
||||
# Ensure the output directory exists
|
||||
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 = []
|
||||
for root, _, files in os.walk(input_dir):
|
||||
for filename in files:
|
||||
if filename.lower().endswith((".jpg", ".jpeg", ".png", ".gif")):
|
||||
image_files.append(os.path.join(root, filename))
|
||||
|
||||
# Convert and process image files synchronously
|
||||
for input_file in image_files:
|
||||
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__":
|
||||
main()
|
||||
|
|
|
@ -10,6 +10,7 @@ function load_image(image) {
|
|||
tileSource: image.tileSource,
|
||||
x: image.x,
|
||||
y: image.y,
|
||||
opacity: 1,
|
||||
success: () => {
|
||||
resolve();
|
||||
},
|
||||
|
@ -40,7 +41,7 @@ fetch('image/image.txt')
|
|||
y: parseInt(parts[2]),
|
||||
red: parseInt(parts[3]),
|
||||
blue: parseInt(parts[4]),
|
||||
green: parseInt(parts[5])
|
||||
green: parseInt(parts[5]),
|
||||
};
|
||||
|
||||
const promise = load_image(dictionary);
|
||||
|
@ -54,7 +55,7 @@ fetch('image/image.txt')
|
|||
})
|
||||
.then(() => {
|
||||
let all_filters = []
|
||||
let all_nav_filters = []
|
||||
|
||||
dictionaries.forEach(image => {
|
||||
let filter = {
|
||||
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_nav_filters.push(nav_filter)
|
||||
});
|
||||
|
||||
|
||||
viewer.navigator.setFilterOptions = viewer.setFilterOptions;
|
||||
|
||||
viewer.setFilterOptions({
|
||||
filters: all_filters
|
||||
});
|
||||
|
||||
viewer.navigator.setFilterOptions({
|
||||
filters: all_nav_filters
|
||||
});
|
||||
|
||||
|
||||
|
||||
})
|
||||
.catch(error => {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
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) => {
|
||||
const clientCount = parseInt(event.data);
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
const viewer = OpenSeadragon({
|
||||
id: "viewer",
|
||||
showNavigator: true,
|
||||
showZoomControl: false,
|
||||
showHomeControl: false,
|
||||
showFullPageControl: false,
|
||||
|
@ -13,9 +12,9 @@ viewer.smartScrollZoom({
|
|||
zoomIncrement: 1000
|
||||
});
|
||||
|
||||
viewer.viewport.minZoomLevel = 0.033;
|
||||
viewer.viewport.minZoomLevel = 0.0125;
|
||||
viewer.viewport.maxZoomLevel = 100;
|
||||
viewer.viewport.defaultZoomLevel = 0.5;
|
||||
viewer.viewport.defaultZoomLevel = 0.0125;
|
||||
viewer.viewport.scrollHandlerSpeed = 1000;
|
||||
viewer.drawer.context.imageSmoothingEnabled = false;
|
||||
viewer.gestureSettingsMouse.clickToZoom = false;
|
||||
|
|
|
@ -12,7 +12,7 @@ body {
|
|||
background-color: #222;
|
||||
background-image: url("image/su.png");
|
||||
background-repeat: no-repeat;
|
||||
background-size: auto;
|
||||
background-size: 1000px;
|
||||
background-position: center;
|
||||
image-rendering: pixelated;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import tornado.ioloop
|
||||
import tornado.web
|
||||
import tornado.websocket
|
||||
from tornado.httpclient import AsyncHTTPClient, HTTPRequest
|
||||
|
||||
class WebSocketHandler(tornado.websocket.WebSocketHandler):
|
||||
clients = set()
|
||||
|
@ -13,6 +14,10 @@ class WebSocketHandler(tornado.websocket.WebSocketHandler):
|
|||
WebSocketHandler.clients.remove(self)
|
||||
self.send_client_count()
|
||||
|
||||
def check_origin(self, origin):
|
||||
# Allow all connections regardless of the origin
|
||||
return True
|
||||
|
||||
def send_client_count(self):
|
||||
count = len(WebSocketHandler.clients)
|
||||
for client in WebSocketHandler.clients:
|
||||
|
@ -21,6 +26,38 @@ class WebSocketHandler(tornado.websocket.WebSocketHandler):
|
|||
except Exception as 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([
|
||||
(r"/funsocket", WebSocketHandler),
|
||||
])
|
||||
|
@ -29,4 +66,3 @@ if __name__ == "__main__":
|
|||
app.listen(8080)
|
||||
print("WebSocket server is running on port 8080")
|
||||
tornado.ioloop.IOLoop.current().start()
|
||||
|
||||
|
|
Loading…
Reference in New Issue