Skip to content

Commit 665b6c8

Browse files
pjt222claude
andcommitted
fix(shiny): pass image_path to SNIC renderer and add default sample image
The rendered_svg() reactive was calling render_puzzle_svg() without image_path, so uploaded images never displayed. Now passes pos$parameters$image_path through to the renderer. Also ships a default sample image (purple asters, 400x600, 146KB) so SNIC puzzles work out of the box without requiring an upload. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 42d7247 commit 665b6c8

3 files changed

Lines changed: 34 additions & 4 deletions

File tree

inst/extdata/sample_image.jpg

142 KB
Loading
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Resize a source photo to a small default sample image for SNIC puzzle demos
2+
# Run once: Rscript inst/scripts/generate_default_image.R
3+
#
4+
# Source: PJT_6805.jpg (purple asters, Norway 2017)
5+
# Photo by Philipp Thoss
6+
7+
if (!requireNamespace("magick", quietly = TRUE)) {
8+
stop("magick package required: install.packages('magick')")
9+
}
10+
11+
source_path <- commandArgs(trailingOnly = TRUE)[1]
12+
if (is.na(source_path) || !file.exists(source_path)) {
13+
stop("Usage: Rscript inst/scripts/generate_default_image.R <path-to-source-image>")
14+
}
15+
output_path <- file.path("inst", "extdata", "sample_image.jpg")
16+
17+
img <- magick::image_read(source_path)
18+
img <- magick::image_resize(img, "400x")
19+
magick::image_write(img, output_path, format = "jpeg", quality = 85)
20+
21+
cat("Default image saved to:", output_path, "\n")
22+
cat("Dimensions:", paste(magick::image_info(img)$width, "x",
23+
magick::image_info(img)$height), "\n")
24+
cat("File size:", file.size(output_path), "bytes\n")

inst/shiny-app/app.R

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,8 +1272,13 @@ build_puzzle_params <- function(input, puzzle_type = NULL) {
12721272
has_fusion <- !is.null(fusion_groups_str) && nchar(trimws(fusion_groups_str)) > 0
12731273

12741274
# SNIC-specific
1275-
image_path_val <- if (puzzle_type == "snic" && !is.null(input$snic_image)) {
1276-
input$snic_image$datapath
1275+
image_path_val <- if (puzzle_type == "snic") {
1276+
if (!is.null(input$snic_image)) {
1277+
input$snic_image$datapath
1278+
} else {
1279+
# Fall back to bundled sample image
1280+
system.file("extdata", "sample_image.jpg", package = "jigsawR")
1281+
}
12771282
} else {
12781283
NULL
12791284
}
@@ -1850,7 +1855,7 @@ server <- function(input, output, session) {
18501855
"concentric" = "Ring-based puzzle radiating from center",
18511856
"voronoi" = "Organic irregular shapes from Voronoi tessellation",
18521857
"random" = "Random Delaunay triangulation shapes",
1853-
"snic" = "Image-aware superpixel segmentation (requires image)",
1858+
"snic" = "Image-aware superpixel segmentation (upload your own or use sample)",
18541859
""
18551860
)
18561861
tags$small(class = "text-muted", desc)
@@ -1927,7 +1932,8 @@ server <- function(input, output, session) {
19271932
show_labels = show_labels_value,
19281933
label_color = label_color_value,
19291934
label_size = label_size_value,
1930-
inline = TRUE # Omit XML declaration for inline HTML embedding
1935+
inline = TRUE, # Omit XML declaration for inline HTML embedding
1936+
image_path = pos$parameters$image_path
19311937
)
19321938
result
19331939
}, error = function(e) {

0 commit comments

Comments
 (0)