Kaynağa Gözat

Generalizing url gen, so it works in a default httpd config

Patrick Augusto 3 yıl önce
ebeveyn
işleme
ca2e262afe
3 değiştirilmiş dosya ile 10 ekleme ve 6 silme
  1. 0 1
      Pixel.html
  2. 7 2
      Pixel.js
  3. 3 3
      Pixel.py

+ 0 - 1
Pixel.html

@@ -2,7 +2,6 @@
 <html>
     <head>
         <meta charset="UTF-8">
-        <link href="https://fonts.googleapis.com/css2?family=Roboto+Mono&display=swap" rel="stylesheet"> 
         <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/flexboxgrid/6.3.1/flexboxgrid.min.css" type="text/css" >
         <link rel="stylesheet" href="Pixel.css">
         <script src="Pixel.js"></script>

+ 7 - 2
Pixel.js

@@ -88,7 +88,10 @@ const draw_ = function(ctx, isize, url, level, images, pos, coords) {
         return images;
     }
 
-    const id = kronecker(pos, [2 ** (level + 1), 2 ** (level + 1)]);
+    const targetImage = kronecker(pos, [2 ** (level + 1), 2 ** (level + 1)]);
+    const idPath = targetImage.substring(0, targetImage.length - 2).match(/.{1,2}/g).join('/');
+    const id = "00/" + idPath + "/" + targetImage + ".jpg";
+    
     const index = images.findIndex((i) => (url + id) == i.image.src);
 
     if (!isInsideSquare(coords, canvas.vertices, isize)) {
@@ -143,7 +146,9 @@ const draw_ = function(ctx, isize, url, level, images, pos, coords) {
 
 const init = function(c) {
     const image = new Image();
-    image.src = canvas.url + "0".repeat((canvas.level + 1) * 2)
+
+    const targetImage = "0".repeat((canvas.level + 1) * 2);
+    image.src = canvas.url + targetImage.match(/.{1,2}/g).join('/').concat("/") + targetImage + ".jpg";
 
     image.onload = () => {
         canvas.width = image.width;

+ 3 - 3
Pixel.py

@@ -6,13 +6,13 @@ import os
 from PIL  import Image, ImageFont, ImageDraw
 from math import log2, pow
 
-from flask import Flask, send_from_directory
+from flask import Flask, send_file
 
 app = Flask(__name__)
 
-@app.route("/image/<string:image>")
+@app.route("/image/<path:image>")
 def serve_image(image):
-    return send_from_directory("00/" + "/".join(a + b for a, b in zip(image[:-2][::2], image[:-2][1::2])) + "/", image + ".jpg")
+    return send_file(image)
 
 def crop(k, dir, im, x, y, sx, sy):
     if (k == 0):