Animation added

This commit is contained in:
2025-11-20 23:38:31 -05:00
parent 9197e464a5
commit cf010974dd
8 changed files with 304 additions and 22 deletions

View File

@@ -201,6 +201,11 @@ def download_maze_image(maze_id):
# Get optional parameters
include_solution = request.args.get('solution', 'false').lower() == 'true'
solver_algorithm = request.args.get('solver', 'bfs')
image_format = request.args.get('format', 'png').lower()
# Validate format
if image_format not in ['png', 'jpg', 'jpeg']:
image_format = 'png'
solution_path = None
visited_cells = None
@@ -215,16 +220,38 @@ def download_maze_image(maze_id):
# Render image
renderer = ImageRenderer(cell_size=20, wall_thickness=2)
filename = f"maze_{maze_id}_{maze.algorithm_used.replace(' ', '_')}"
# Use absolute path for output directory
output_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'output_images')
os.makedirs(output_dir, exist_ok=True)
filepath = renderer.render(
maze,
filename,
directory=output_dir,
solution_path=solution_path,
visited_cells=visited_cells
visited_cells=visited_cells,
format=image_format
)
return send_file(filepath, mimetype='image/png', as_attachment=True)
# Verify file exists
if not os.path.exists(filepath):
return jsonify({'error': 'Failed to generate image file'}), 500
# Determine mimetype and download name
mimetype = 'image/jpeg' if image_format in ['jpg', 'jpeg'] else 'image/png'
download_name = os.path.basename(filepath)
return send_file(
filepath,
mimetype=mimetype,
as_attachment=True,
download_name=download_name
)
except Exception as e:
import traceback
traceback.print_exc()
return jsonify({'error': str(e)}), 500