MCPcopy Index your code
hub / github.com/python-openxml/python-docx / scaled_dimensions

Method scaled_dimensions

src/docx/image/image.py:116–146  ·  view source on GitHub ↗

(cx, cy) pair representing scaled dimensions of this image. The native dimensions of the image are scaled by applying the following rules to the `width` and `height` arguments. * If both `width` and `height` are specified, the return value is (`width`, `height`); no

(
        self, width: int | Length | None = None, height: int | Length | None = None
    )

Source from the content-addressed store, hash-verified

114 return Inches(self.px_height / self.vert_dpi)
115
116 def scaled_dimensions(
117 self, width: int | Length | None = None, height: int | Length | None = None
118 ) -> Tuple[Length, Length]:
119 """(cx, cy) pair representing scaled dimensions of this image.
120
121 The native dimensions of the image are scaled by applying the following rules to
122 the `width` and `height` arguments.
123
124 * If both `width` and `height` are specified, the return value is (`width`,
125 `height`); no scaling is performed.
126 * If only one is specified, it is used to compute a scaling factor that is then
127 applied to the unspecified dimension, preserving the aspect ratio of the image.
128 * If both `width` and `height` are |None|, the native dimensions are returned.
129
130 The native dimensions are calculated using the dots-per-inch (dpi) value
131 embedded in the image, defaulting to 72 dpi if no value is specified, as is
132 often the case. The returned values are both |Length| objects.
133 """
134 if width is None and height is None:
135 return self.width, self.height
136
137 if width is None:
138 assert height is not None
139 scaling_factor = float(height) / float(self.height)
140 width = round(self.width * scaling_factor)
141
142 if height is None:
143 scaling_factor = float(width) / float(self.width)
144 height = round(self.height * scaling_factor)
145
146 return Emu(width), Emu(height)
147
148 @lazyproperty
149 def sha1(self):

Callers 2

new_pic_inlineMethod · 0.80

Calls 1

EmuClass · 0.90

Tested by 1