Giter Site home page Giter Site logo

Comments (3)

Argmaster avatar Argmaster commented on June 14, 2024

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.

Argmaster avatar Argmaster commented on June 14, 2024

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.

Pauloretty avatar Pauloretty commented on June 14, 2024

Yep, a few simple calculations with LayerProperties.target_bounding_box and LayerProperties.target_coordinate_origin solved my problem. Thanks!

from pygerber.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.