Comments (3)
Yes, but it is not as straight forward as one might wanted it to be. What you are after is coordinate origin and bounding box of all draw commands. both of those can be for sure extracted from Backend instance, when you are directly instantiating Tokenizer, Parser and Backend classes. I am not sure if it is currently possible with high level API and it is not possible with CLI. You will still have to manually resize individual images to match biggest one and reposition them to make their coordinate origins match, but it is possible. I'll provide more details soon.
from pygerber.
I was mistaken about high level API not being enough to handle this issue, you can use RenderingResult.get_properties() to extract LayerProperties object. See example below, based on example from readme.
from __future__ import annotations
from io import BytesIO # noqa: D100
from PIL import Image
from pygerber.gerberx3.api import (
ColorScheme,
Rasterized2DLayer,
Rasterized2DLayerParams,
)
source_code = """
%FSLAX26Y26*%
%MOMM*%
%ADD100R,1.5X1.0X0.5*%
%ADD200C,1.5X1.0*%
%ADD300O,1.5X1.0X0.6*%
%ADD400P,1.5X3X5.0*%
D100*
X0Y0D03*
D200*
X0Y2000000D03*
D300*
X2000000Y0D03*
D400*
X2000000Y2000000D03*
M02*
"""
result = Rasterized2DLayer(
options=Rasterized2DLayerParams(
source_code=source_code,
colors=ColorScheme.SILK,
dpi=3000,
),
).render()
output = BytesIO()
result.save(output, format="png")
output.seek(0)
Image.open(output).show()
p = result.get_properties()
print(p.gerber_bounding_box)
print(p.gerber_coordinate_origin)
print(p.target_bounding_box)
print(p.target_coordinate_origin)
Difference between gerber_* and target_* is insignificant in our case, I'd recommend sticking to target_* ones, as they refer to actual image.
See LayerProperties in docs.
from pygerber.
Yep, a few simple calculations with LayerProperties.target_bounding_box and LayerProperties.target_coordinate_origin solved my problem. Thanks!
from pygerber.
Related Issues (20)
- Change language server to rely on Parser2 for introspection
- Create Gerber code debugger
- Fix duplicated element prefixes in docs
- Add raster image renderer for Parser2
- Fix feature support counts for SvgRenderer2
- Fix incorrect behavior of block aperture definitions.
- %TF.SameCoordinates*% shown as "Invalid Syntax"
- Unify visitor implementation for Parser2 with ASTVisitor
- Missing pads on render of KiCad demo USB stick HOT 8
- Release 2.3.0
- V2 API incorrect pad rotation HOT 3
- Release 2.3.1
- Gerber code builder
- Add command line interface for Parser2 and friends
- Release 2.4.0
- Release 2.5.0
- Refactor unit test suite
- Parser Fails on Empty G04* command
- Incorrect Board Outline Rendering HOT 5
- Release 2.3.2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pygerber.