rs-web 0.4.2

A fast, Lua-driven static site generator with encryption support
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
//! Image processing module (rs.image)
//!
//! Image operations:
//! - rs.image.dimensions, rs.image.resize, rs.image.convert, rs.image.optimize (sequential)
//! - rs.image.par.resize, rs.image.par.convert, rs.image.par.optimize (parallel)

use crate::tracker::SharedTracker;
use image::DynamicImage;
use mlua::{Lua, Result, Table, Value};
use rayon::prelude::*;
use std::path::{Path, PathBuf};

/// Apply EXIF orientation to an image
fn apply_exif_orientation(img: DynamicImage, path: &Path) -> DynamicImage {
    use std::fs::File;
    use std::io::BufReader;

    let file = match File::open(path) {
        Ok(f) => f,
        Err(_) => return img,
    };

    let exif = match exif::Reader::new().read_from_container(&mut BufReader::new(file)) {
        Ok(e) => e,
        Err(_) => return img,
    };

    let orientation = exif
        .get_field(exif::Tag::Orientation, exif::In::PRIMARY)
        .and_then(|f| f.value.get_uint(0))
        .unwrap_or(1);

    // Apply transformation based on EXIF orientation
    match orientation {
        1 => img,
        2 => img.fliph(),
        3 => img.rotate180(),
        4 => img.flipv(),
        5 => img.rotate90().fliph(),
        6 => img.rotate90(),
        7 => img.rotate270().fliph(),
        8 => img.rotate270(),
        _ => img,
    }
}

/// Resolve path relative to project root
fn resolve_path(path: &str, root: &Path) -> PathBuf {
    if Path::new(path).is_absolute() {
        PathBuf::from(path)
    } else {
        root.join(path)
    }
}

/// Create the image module table
pub fn create_module(lua: &Lua, project_root: &Path, tracker: SharedTracker) -> Result<Table> {
    let image_mod = lua.create_table()?;
    let root = project_root.to_path_buf();

    // ========================================================================
    // Sequential Operations
    // ========================================================================

    // dimensions(path) - Get image width and height
    let root_clone = root.clone();
    let tracker_clone = tracker.clone();
    let dimensions_fn = lua.create_function(move |lua, path: String| {
        use image::GenericImageView;

        let full_path = resolve_path(&path, &root_clone);

        if let Ok(content) = std::fs::read(&full_path) {
            let canonical = full_path
                .canonicalize()
                .unwrap_or_else(|_| full_path.clone());
            tracker_clone.record_read(canonical, &content);
        }

        match image::open(&full_path) {
            Ok(img) => {
                let img = apply_exif_orientation(img, &full_path);
                let (width, height) = img.dimensions();
                let result = lua.create_table()?;
                result.set("width", width)?;
                result.set("height", height)?;
                Ok(Value::Table(result))
            }
            Err(_) => Ok(Value::Nil),
        }
    })?;
    image_mod.set("dimensions", dimensions_fn)?;

    // resize(input, output, options) - Resize image
    // options: { width: number, height?: number, quality?: number }
    let root_clone = root.clone();
    let tracker_clone = tracker.clone();
    let resize_fn = lua.create_function(
        move |_lua, (input, output, options): (String, String, Table)| {
            use image::{GenericImageView, imageops};

            let width: u32 = options
                .get("width")
                .map_err(|_| mlua::Error::external("image.resize requires options.width"))?;
            let height: Option<u32> = options.get("height").ok();
            let quality: f32 = options.get("quality").unwrap_or(85.0);

            let input_path = resolve_path(&input, &root_clone);
            let output_path = resolve_path(&output, &root_clone);

            let input_content = std::fs::read(&input_path)
                .map_err(|e| mlua::Error::external(format!("Failed to read image: {}", e)))?;
            let input_canonical = input_path
                .canonicalize()
                .unwrap_or_else(|_| input_path.clone());
            tracker_clone.record_read(input_canonical, &input_content);

            let img = image::open(&input_path)
                .map_err(|e| mlua::Error::external(format!("Failed to open image: {}", e)))?;
            let img = apply_exif_orientation(img, &input_path);

            let (orig_w, orig_h) = img.dimensions();
            let new_height =
                height.unwrap_or_else(|| (orig_h as f64 * (width as f64 / orig_w as f64)) as u32);

            let resized = DynamicImage::ImageRgba8(imageops::resize(
                &img,
                width,
                new_height,
                imageops::FilterType::Lanczos3,
            ));

            if let Some(parent) = output_path.parent() {
                std::fs::create_dir_all(parent).map_err(|e| {
                    mlua::Error::external(format!("Failed to create directory: {}", e))
                })?;
            }

            let ext = output_path
                .extension()
                .and_then(|e| e.to_str())
                .map(|e| e.to_lowercase())
                .unwrap_or_else(|| "png".to_string());

            match ext.as_str() {
                "webp" => {
                    let encoder = webp::Encoder::from_image(&resized)
                        .map_err(|e| mlua::Error::external(format!("WebP encode error: {}", e)))?;
                    let webp = encoder.encode(quality);
                    std::fs::write(&output_path, &*webp)
                        .map_err(|e| mlua::Error::external(format!("Failed to write: {}", e)))?;
                    let output_canonical = output_path.canonicalize().unwrap_or(output_path);
                    tracker_clone.record_write(output_canonical, &webp);
                }
                _ => {
                    resized
                        .save(&output_path)
                        .map_err(|e| mlua::Error::external(format!("Failed to save: {}", e)))?;
                    if let Ok(output_content) = std::fs::read(&output_path) {
                        let output_canonical = output_path.canonicalize().unwrap_or(output_path);
                        tracker_clone.record_write(output_canonical, &output_content);
                    }
                }
            }

            Ok(Value::Boolean(true))
        },
    )?;
    image_mod.set("resize", resize_fn)?;

    // convert(input, output, options?) - Convert image format
    // options: { format?: string, quality?: number }
    let root_clone = root.clone();
    let tracker_clone = tracker.clone();
    let convert_fn = lua.create_function(
        move |_lua, (input, output, options): (String, String, Option<Table>)| {
            let format: Option<String> = options.as_ref().and_then(|t| t.get("format").ok());
            let quality: f32 = options
                .as_ref()
                .and_then(|t| t.get::<f32>("quality").ok())
                .unwrap_or(85.0);

            let input_path = resolve_path(&input, &root_clone);
            let output_path = resolve_path(&output, &root_clone);

            let input_content = std::fs::read(&input_path)
                .map_err(|e| mlua::Error::external(format!("Failed to read image: {}", e)))?;
            let input_canonical = input_path
                .canonicalize()
                .unwrap_or_else(|_| input_path.clone());
            tracker_clone.record_read(input_canonical, &input_content);

            let img = image::open(&input_path)
                .map_err(|e| mlua::Error::external(format!("Failed to open image: {}", e)))?;
            let img = apply_exif_orientation(img, &input_path);

            if let Some(parent) = output_path.parent() {
                std::fs::create_dir_all(parent).map_err(|e| {
                    mlua::Error::external(format!("Failed to create directory: {}", e))
                })?;
            }

            let ext = format.unwrap_or_else(|| {
                output_path
                    .extension()
                    .and_then(|e| e.to_str())
                    .map(|e| e.to_lowercase())
                    .unwrap_or_else(|| "png".to_string())
            });

            match ext.as_str() {
                "webp" => {
                    let encoder = webp::Encoder::from_image(&img)
                        .map_err(|e| mlua::Error::external(format!("WebP encode error: {}", e)))?;
                    let webp = encoder.encode(quality);
                    std::fs::write(&output_path, &*webp)
                        .map_err(|e| mlua::Error::external(format!("Failed to write: {}", e)))?;
                    let output_canonical = output_path.canonicalize().unwrap_or(output_path);
                    tracker_clone.record_write(output_canonical, &webp);
                }
                _ => {
                    img.save(&output_path)
                        .map_err(|e| mlua::Error::external(format!("Failed to save: {}", e)))?;
                    if let Ok(output_content) = std::fs::read(&output_path) {
                        let output_canonical = output_path.canonicalize().unwrap_or(output_path);
                        tracker_clone.record_write(output_canonical, &output_content);
                    }
                }
            }

            Ok(Value::Boolean(true))
        },
    )?;
    image_mod.set("convert", convert_fn)?;

    // optimize(input, output, options?) - Optimize/compress image
    // options: { quality?: number }
    let root_clone = root.clone();
    let tracker_clone = tracker.clone();
    let optimize_fn = lua.create_function(
        move |_lua, (input, output, options): (String, String, Option<Table>)| {
            let quality: f32 = options
                .as_ref()
                .and_then(|t| t.get::<f32>("quality").ok())
                .unwrap_or(85.0);

            let input_path = resolve_path(&input, &root_clone);
            let output_path = resolve_path(&output, &root_clone);

            let input_content = std::fs::read(&input_path)
                .map_err(|e| mlua::Error::external(format!("Failed to read image: {}", e)))?;
            let input_canonical = input_path
                .canonicalize()
                .unwrap_or_else(|_| input_path.clone());
            tracker_clone.record_read(input_canonical, &input_content);

            let img = image::open(&input_path)
                .map_err(|e| mlua::Error::external(format!("Failed to open image: {}", e)))?;
            let img = apply_exif_orientation(img, &input_path);

            if let Some(parent) = output_path.parent() {
                std::fs::create_dir_all(parent).map_err(|e| {
                    mlua::Error::external(format!("Failed to create directory: {}", e))
                })?;
            }

            let ext = output_path
                .extension()
                .and_then(|e| e.to_str())
                .map(|e| e.to_lowercase())
                .unwrap_or_else(|| "webp".to_string());

            match ext.as_str() {
                "webp" => {
                    let encoder = webp::Encoder::from_image(&img)
                        .map_err(|e| mlua::Error::external(format!("WebP encode error: {}", e)))?;
                    let webp = encoder.encode(quality);
                    std::fs::write(&output_path, &*webp)
                        .map_err(|e| mlua::Error::external(format!("Failed to write: {}", e)))?;
                    let output_canonical = output_path.canonicalize().unwrap_or(output_path);
                    tracker_clone.record_write(output_canonical, &webp);
                }
                _ => {
                    img.save(&output_path)
                        .map_err(|e| mlua::Error::external(format!("Failed to save: {}", e)))?;
                    if let Ok(output_content) = std::fs::read(&output_path) {
                        let output_canonical = output_path.canonicalize().unwrap_or(output_path);
                        tracker_clone.record_write(output_canonical, &output_content);
                    }
                }
            }

            Ok(Value::Boolean(true))
        },
    )?;
    image_mod.set("optimize", optimize_fn)?;

    // ========================================================================
    // Parallel Operations (rs.image.par.*)
    // ========================================================================

    let par = lua.create_table()?;

    // par.resize(inputs, outputs, options) - Resize multiple images in parallel
    // options: { width: number, height?: number, quality?: number }
    let root_clone = root.clone();
    let tracker_clone = tracker.clone();
    let par_resize_fn = lua.create_function(
        move |lua, (inputs, outputs, options): (Table, Table, Table)| {
            use image::{GenericImageView, imageops};

            let input_list: Vec<String> = inputs
                .sequence_values::<String>()
                .filter_map(|r| r.ok())
                .collect();
            let output_list: Vec<String> = outputs
                .sequence_values::<String>()
                .filter_map(|r| r.ok())
                .collect();

            if input_list.len() != output_list.len() {
                return Err(mlua::Error::external(
                    "image.par.resize: inputs and outputs must have same length",
                ));
            }

            let width: u32 = options
                .get("width")
                .map_err(|_| mlua::Error::external("image.par.resize requires options.width"))?;
            let height: Option<u32> = options.get("height").ok();
            let quality: f32 = options.get("quality").unwrap_or(85.0);

            let pairs: Vec<_> = input_list.into_iter().zip(output_list).collect();
            let tracker_ref = &tracker_clone;
            let root_ref = &root_clone;

            let results: Vec<std::result::Result<(), String>> = pairs
                .par_iter()
                .map(|(input, output)| {
                    let input_path = resolve_path(input, root_ref);
                    let output_path = resolve_path(output, root_ref);

                    let input_content = std::fs::read(&input_path)
                        .map_err(|e| format!("Failed to read {}: {}", input, e))?;
                    let input_canonical = input_path.canonicalize().unwrap_or(input_path.clone());
                    tracker_ref.record_read(input_canonical, &input_content);

                    let img = image::open(&input_path)
                        .map_err(|e| format!("Failed to open {}: {}", input, e))?;
                    let img = apply_exif_orientation(img, &input_path);

                    let (orig_w, orig_h) = img.dimensions();
                    let new_height = height
                        .unwrap_or_else(|| (orig_h as f64 * (width as f64 / orig_w as f64)) as u32);

                    let resized = DynamicImage::ImageRgba8(imageops::resize(
                        &img,
                        width,
                        new_height,
                        imageops::FilterType::Lanczos3,
                    ));

                    if let Some(parent) = output_path.parent() {
                        std::fs::create_dir_all(parent)
                            .map_err(|e| format!("Failed to create directory: {}", e))?;
                    }

                    let ext = output_path
                        .extension()
                        .and_then(|e| e.to_str())
                        .map(|e| e.to_lowercase())
                        .unwrap_or_else(|| "png".to_string());

                    let output_bytes = match ext.as_str() {
                        "webp" => {
                            let encoder = webp::Encoder::from_image(&resized)
                                .map_err(|e| format!("WebP encode error: {}", e))?;
                            encoder.encode(quality).to_vec()
                        }
                        "jpg" | "jpeg" => {
                            let mut buf = Vec::new();
                            let mut cursor = std::io::Cursor::new(&mut buf);
                            resized
                                .write_to(&mut cursor, image::ImageFormat::Jpeg)
                                .map_err(|e| format!("JPEG encode error: {}", e))?;
                            buf
                        }
                        "png" => {
                            let mut buf = Vec::new();
                            let mut cursor = std::io::Cursor::new(&mut buf);
                            resized
                                .write_to(&mut cursor, image::ImageFormat::Png)
                                .map_err(|e| format!("PNG encode error: {}", e))?;
                            buf
                        }
                        _ => return Err(format!("Unsupported output format: {}", ext)),
                    };

                    std::fs::write(&output_path, &output_bytes)
                        .map_err(|e| format!("Failed to write {}: {}", output, e))?;

                    let output_canonical = output_path.canonicalize().unwrap_or(output_path);
                    tracker_ref.record_write(output_canonical, &output_bytes);

                    Ok(())
                })
                .collect();

            let result_table = lua.create_table()?;
            for (i, result) in results.into_iter().enumerate() {
                match result {
                    Ok(()) => result_table.set(i + 1, true)?,
                    Err(e) => result_table.set(i + 1, e)?,
                }
            }
            Ok(result_table)
        },
    )?;
    par.set("resize", par_resize_fn)?;

    // par.convert(inputs, outputs, options?) - Convert multiple images in parallel
    // options: { quality?: number }
    let root_clone = root.clone();
    let tracker_clone = tracker.clone();
    let par_convert_fn = lua.create_function(
        move |lua, (inputs, outputs, options): (Table, Table, Option<Table>)| {
            let input_list: Vec<String> = inputs
                .sequence_values::<String>()
                .filter_map(|r| r.ok())
                .collect();
            let output_list: Vec<String> = outputs
                .sequence_values::<String>()
                .filter_map(|r| r.ok())
                .collect();

            if input_list.len() != output_list.len() {
                return Err(mlua::Error::external(
                    "image.par.convert: inputs and outputs must have same length",
                ));
            }

            let quality: f32 = options
                .as_ref()
                .and_then(|t| t.get("quality").ok())
                .unwrap_or(85.0);

            let pairs: Vec<_> = input_list.into_iter().zip(output_list).collect();
            let tracker_ref = &tracker_clone;
            let root_ref = &root_clone;

            let results: Vec<std::result::Result<(), String>> = pairs
                .par_iter()
                .map(|(input, output)| {
                    let input_path = resolve_path(input, root_ref);
                    let output_path = resolve_path(output, root_ref);

                    let content = std::fs::read(&input_path)
                        .map_err(|e| format!("Failed to read {}: {}", input, e))?;

                    let input_canonical = input_path.canonicalize().unwrap_or(input_path.clone());
                    tracker_ref.record_read(input_canonical, &content);

                    let img = image::open(&input_path)
                        .map_err(|e| format!("Failed to open image {}: {}", input, e))?;
                    let img = apply_exif_orientation(img, &input_path);

                    if let Some(parent) = output_path.parent() {
                        std::fs::create_dir_all(parent)
                            .map_err(|e| format!("Failed to create directory: {}", e))?;
                    }

                    let ext = output_path
                        .extension()
                        .and_then(|e| e.to_str())
                        .map(|e| e.to_lowercase())
                        .unwrap_or_else(|| "png".to_string());

                    let output_bytes = match ext.as_str() {
                        "webp" => {
                            let encoder = webp::Encoder::from_image(&img)
                                .map_err(|e| format!("WebP encoder error: {}", e))?;
                            encoder.encode(quality).to_vec()
                        }
                        "jpg" | "jpeg" => {
                            let mut buf = Vec::new();
                            let mut cursor = std::io::Cursor::new(&mut buf);
                            img.write_to(&mut cursor, image::ImageFormat::Jpeg)
                                .map_err(|e| format!("JPEG encode error: {}", e))?;
                            buf
                        }
                        "png" => {
                            let mut buf = Vec::new();
                            let mut cursor = std::io::Cursor::new(&mut buf);
                            img.write_to(&mut cursor, image::ImageFormat::Png)
                                .map_err(|e| format!("PNG encode error: {}", e))?;
                            buf
                        }
                        _ => return Err(format!("Unsupported output format: {}", ext)),
                    };

                    std::fs::write(&output_path, &output_bytes)
                        .map_err(|e| format!("Failed to write {}: {}", output, e))?;

                    let output_canonical = output_path.canonicalize().unwrap_or(output_path);
                    tracker_ref.record_write(output_canonical, &output_bytes);

                    Ok(())
                })
                .collect();

            let result_table = lua.create_table()?;
            for (i, result) in results.into_iter().enumerate() {
                match result {
                    Ok(()) => result_table.set(i + 1, true)?,
                    Err(e) => result_table.set(i + 1, e)?,
                }
            }
            Ok(result_table)
        },
    )?;
    par.set("convert", par_convert_fn)?;

    // par.optimize(inputs, outputs, options?) - Optimize multiple images in parallel
    // options: { quality?: number }
    let root_clone = root.clone();
    let tracker_clone = tracker.clone();
    let par_optimize_fn = lua.create_function(
        move |lua, (inputs, outputs, options): (Table, Table, Option<Table>)| {
            let input_list: Vec<String> = inputs
                .sequence_values::<String>()
                .filter_map(|r| r.ok())
                .collect();
            let output_list: Vec<String> = outputs
                .sequence_values::<String>()
                .filter_map(|r| r.ok())
                .collect();

            if input_list.len() != output_list.len() {
                return Err(mlua::Error::external(
                    "image.par.optimize: inputs and outputs must have same length",
                ));
            }

            let quality: f32 = options
                .as_ref()
                .and_then(|t| t.get("quality").ok())
                .unwrap_or(85.0);

            let pairs: Vec<_> = input_list.into_iter().zip(output_list).collect();
            let tracker_ref = &tracker_clone;
            let root_ref = &root_clone;

            let results: Vec<std::result::Result<(), String>> = pairs
                .par_iter()
                .map(|(input, output)| {
                    let input_path = resolve_path(input, root_ref);
                    let output_path = resolve_path(output, root_ref);

                    let content = std::fs::read(&input_path)
                        .map_err(|e| format!("Failed to read {}: {}", input, e))?;

                    let input_canonical = input_path.canonicalize().unwrap_or(input_path.clone());
                    tracker_ref.record_read(input_canonical, &content);

                    let img = image::open(&input_path)
                        .map_err(|e| format!("Failed to open image {}: {}", input, e))?;
                    let img = apply_exif_orientation(img, &input_path);

                    if let Some(parent) = output_path.parent() {
                        std::fs::create_dir_all(parent)
                            .map_err(|e| format!("Failed to create directory: {}", e))?;
                    }

                    let ext = output_path
                        .extension()
                        .and_then(|e| e.to_str())
                        .map(|e| e.to_lowercase())
                        .unwrap_or_else(|| "webp".to_string());

                    let output_bytes = match ext.as_str() {
                        "webp" => {
                            let encoder = webp::Encoder::from_image(&img)
                                .map_err(|e| format!("WebP encoder error: {}", e))?;
                            encoder.encode(quality).to_vec()
                        }
                        "jpg" | "jpeg" => {
                            let mut buf = Vec::new();
                            let mut cursor = std::io::Cursor::new(&mut buf);
                            img.write_to(&mut cursor, image::ImageFormat::Jpeg)
                                .map_err(|e| format!("JPEG encode error: {}", e))?;
                            buf
                        }
                        "png" => {
                            let mut buf = Vec::new();
                            let mut cursor = std::io::Cursor::new(&mut buf);
                            img.write_to(&mut cursor, image::ImageFormat::Png)
                                .map_err(|e| format!("PNG encode error: {}", e))?;
                            buf
                        }
                        _ => return Err(format!("Unsupported output format: {}", ext)),
                    };

                    std::fs::write(&output_path, &output_bytes)
                        .map_err(|e| format!("Failed to write {}: {}", output, e))?;

                    let output_canonical = output_path.canonicalize().unwrap_or(output_path);
                    tracker_ref.record_write(output_canonical, &output_bytes);

                    Ok(())
                })
                .collect();

            let result_table = lua.create_table()?;
            for (i, result) in results.into_iter().enumerate() {
                match result {
                    Ok(()) => result_table.set(i + 1, true)?,
                    Err(e) => result_table.set(i + 1, e)?,
                }
            }
            Ok(result_table)
        },
    )?;
    par.set("optimize", par_optimize_fn)?;

    image_mod.set("par", par)?;

    Ok(image_mod)
}