File: image.rst

package info (click to toggle)
ezdxf 0.18.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 46,952 kB
  • sloc: python: 158,141; javascript: 166; cpp: 138; makefile: 116; lisp: 20
file content (45 lines) | stat: -rw-r--r-- 1,149 bytes parent folder | download
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
.. _tut_image:

Tutorial for Image and ImageDef
===============================

Insert a raster image into a DXF document, the raster image is NOT embedded in
the DXF file:

.. code-block:: Python

    import ezdxf

    # The IMAGE entity requires the DXF R2000 format or later.
    doc = ezdxf.new("R2000")

    # The IMAGEDEF entity is like a block definition, it just defines the image.
    my_image_def = doc.add_image_def(
        filename="mycat.jpg", size_in_pixel=(640, 360)
    )


    msp = doc.modelspace()
    # The IMAGE entity is like the INSERT entity, it's just an image reference,
    # and there can be multiple references to the same picture in a DXF document.

    # 1st image reference
    msp.add_image(
        insert=(2, 1),
        size_in_units=(6.4, 3.6),
        image_def=my_image_def,
        rotation=0
    )
    # 2nd image reference
    msp.add_image(
        insert=(4, 5),
        size_in_units=(3.2, 1.8),
        image_def=my_image_def,
        rotation=30
    )

    # Get existing image definitions from the OBJECTS section:
    image_defs = doc.objects.query("IMAGEDEF")

    doc.saveas("dxf_with_cat.dxf")