diff --git a/docs/getting_started.md b/docs/getting_started.md index 378697d..2861736 100644 --- a/docs/getting_started.md +++ b/docs/getting_started.md @@ -11,10 +11,10 @@ pip install pyfdl ```python import pyfdl -from pyfdl import FDL, Canvas, FramingIntent, DimensionsInt, DimensionsFloat, Point +from pyfdl import Canvas, FramingIntent, DimensionsInt, DimensionsFloat, Point from io import StringIO -fdl = FDL() +fdl = pyfdl.FDL() # Applying defaults will provide you with a valid staring point fdl.apply_defaults() @@ -54,3 +54,31 @@ canvas.place_framing_intent(framing_intent=framing_intent) with StringIO() as f: pyfdl.dump(fdl, f, validate=True) ``` + +## Create a Canvas from a Canvas Template +```python +import pyfdl +from io import StringIO +from pathlib import Path + +fdl_file = Path('tests/sample_data/Scenario-9__OriginalFDL_UsedToMakePlate.fdl') +with fdl_file.open('r') as f: + fdl = pyfdl.load(f) + +# Select the first canvas in the first context +source_canvas = fdl.contexts[0].canvases[0] + +# Select the first canvas template +canvas_template = fdl.canvas_templates[0] + +# We know we want to use the first framing decision of the source canvas, so we pass 0 +# You may also pass the actual `FramingDecision` source_canvas.framing_decisions[0] +new_canvas = pyfdl.Canvas.from_canvas_template(canvas_template, source_canvas, 0) + +# Place the new canvas along side the source +fdl.contexts[0].canvases.add_item(new_canvas) + +# Validate and "save" +with StringIO() as f: + pyfdl.dump(fdl, f, validate=True) +``` diff --git a/src/pyfdl/canvas.py b/src/pyfdl/canvas.py index 721b110..dc008da 100644 --- a/src/pyfdl/canvas.py +++ b/src/pyfdl/canvas.py @@ -101,9 +101,9 @@ def from_canvas_template( based on a [CanvasTemplate](canvas_template.md#Canvas Template) Args: - canvas_template: - source_canvas: - source_framing_decision: + canvas_template: describing how to handle incoming `Canvas` and `FramingDecision` + source_canvas: to use as base for new canvas + source_framing_decision: either a `FramingDecision` from the source canvas or the index (`int`) of one. Returns: canvas: based on the provided canvas template and sources @@ -114,7 +114,7 @@ def from_canvas_template( canvas = Canvas( label=canvas_template.label, - _id=Base.generate_uuid().strip('-'), + _id=Base.generate_uuid().replace('-', ''), source_canvas_id=source_canvas.id, anamorphic_squeeze=canvas_template.target_anamorphic_squeeze ) diff --git a/tests/sample_data/Scenario-9__OriginalFDL_UsedToMakePlate.fdl b/tests/sample_data/Scenario-9__OriginalFDL_UsedToMakePlate.fdl new file mode 100644 index 0000000..09c3f3d --- /dev/null +++ b/tests/sample_data/Scenario-9__OriginalFDL_UsedToMakePlate.fdl @@ -0,0 +1,50 @@ +{ + "uuid": "6FBE1EBC-50A0-4201-90E0-76C98DFFD04C", + "version": {"major": 0, "minor": 1}, + "fdl_creator": "ASC FDL Committee", + "default_framing_intent": "FDLSMP03", + "framing_intents": [{ + "label": "1.78-1 Framing", + "id": "FDLSMP03", + "aspect_ratio": {"width": 16, "height": 9}, + "protection": 0.088 + } + ], + "contexts": [{ + "label": "PanavisionDXL2", + "context_creator": "ASC FDL Committee", + "canvases": [{ + "label": "Open Gate RAW", + "id": "20220310", + "source_canvas_id": "20220310", + "dimensions": {"width": 5184, "height": 4320}, + "effective_dimensions": {"width": 5184, "height": 4320}, + "effective_anchor_point": {"x": 0, "y": 0}, + "photosite_dimensions": {"width": 5184, "height": 4320}, + "physical_dimensions": {"width": 25.92, "height": 21.60}, + "anamorphic_squeeze": 1.30, + "framing_decisions": [{ + "label": "1.78-1 Framing", + "id": "20220310-FDLSMP03", + "framing_intent_id": "FDLSMP03", + "dimensions": {"width": 4728, "height": 3456}, + "anchor_point": {"x": 228, "y": 432}, + "protection_dimensions": {"width": 5184, "height": 3790}, + "protection_anchor_point": {"x": 0, "y": 265} + } + ] + }] + }], + "canvas_templates": [{ + "label": "VFX Pull", + "id": "VX220310", + "target_dimensions": {"width": 4096, "height": 2304}, + "target_anamorphic_squeeze": 1.00, + "fit_source": "framing_decision.dimensions", + "fit_method": "width", + "alignment_method_vertical": "center", + "alignment_method_horizontal": "center", + "preserve_from_source_canvas": "canvas.dimensions", + "round": {"even": "even", "mode": "up"} + }] +} \ No newline at end of file