Skip to content

Commit

Permalink
Canvas Template example in docs (#17)
Browse files Browse the repository at this point in the history
Added and example of creating a canvas from a canvas template
Added an additional sample file

Signed-off-by: apetrynet <flehnerheener@gmail.com>
  • Loading branch information
apetrynet authored Jun 21, 2024
1 parent 6945c28 commit b40b8fc
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 6 deletions.
32 changes: 30 additions & 2 deletions docs/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
```
8 changes: 4 additions & 4 deletions src/pyfdl/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
)
Expand Down
50 changes: 50 additions & 0 deletions tests/sample_data/Scenario-9__OriginalFDL_UsedToMakePlate.fdl
Original file line number Diff line number Diff line change
@@ -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"}
}]
}

0 comments on commit b40b8fc

Please sign in to comment.