open xml how to set picture size

open xml how to set picture size

Open XML: A Complete Information to Setting Image Measurement

Introduction

Greetings, readers! Welcome to our in-depth information on easy methods to grasp image measurement adjustment in Open XML paperwork. Whether or not you are an skilled developer or simply beginning out, this text will give you all of the information you must seamlessly resize pictures in your Open XML paperwork.

Understanding Image Measurement in Open XML

Open XML makes use of the DrawingML namespace to retailer and manipulate pictures. Inside the DrawingML hierarchy, the <pic> component represents the image itself. To specify the dimensions of the image, it’s essential to modify the width and peak attributes of the <pic> component. These attributes specify the width and peak of the image in factors (pt), the place 1 pt equals roughly 1/72 inch.

Setting Image Measurement Programmatically

You may programmatically set the image measurement in Open XML utilizing varied strategies. Listed here are two widespread approaches:

Utilizing the Open XML SDK

The Open XML SDK offers a complete set of courses for working with Open XML paperwork. To set image measurement utilizing the SDK, observe these steps:

  1. Open the doc and find the <pic> component representing the image you need to resize.
  2. Entry the Width and Top properties of the <pic> component.
  3. Set the width and peak values in factors.

Utilizing Open XML Productiveness Instrument

Should you’re comfy working with XML, you may straight modify the Open XML markup to set image measurement. Open the doc in an XML editor and find the <pic> component. Inside the <pic> component, modify the width and peak attributes with the specified values.

Desk: Widespread Image Sizes

Image Measurement (pt) Pixel Measurement (px) Decision (dpi)
150 x 150 150 x 150 72
300 x 300 300 x 300 72
600 x 600 600 x 600 72
1200 x 1200 1200 x 1200 72
2400 x 2400 2400 x 2400 72

Sustaining Side Ratio

When resizing photos, it is typically essential to keep up the unique side ratio to keep away from distortion. To do that, you need to use the scale attribute of the <pic> component. By setting scale to 1, the image is scaled proportionally, preserving its side ratio.

Conclusion

Congratulations, readers! You now have an intensive understanding of easy methods to set image measurement in Open XML paperwork. Whether or not you select to make use of the Open XML SDK or modify the XML markup straight, the methods outlined on this article will empower you to exactly management the looks of pictures in your paperwork.

Discover different articles on our web site to additional improve your Open XML information. Comfortable coding!

FAQ about Open XML – Tips on how to set image measurement

How do I set the peak of an image?

The peak of an image could be set utilizing the peak attribute of the <pic:blipFill> component. The worth of the peak attribute is laid out in English Metric Items (EMU), the place 1 EMU is the same as 0.001 inch. For instance, to set the peak of an image to 1 inch, you’ll use the next code:

<pic:blipFill>
    <a:blip r:embed="rId2"/>
    <a:stretch>
        <a:fillRect/>
        <a:stretchProp>
            <a:fillRect/>
            <a:stretchProp val="1000000"/>
        </a:stretchProp>
    </a:stretch>
</pic:blipFill>

How do I set the width of an image?

The width of an image could be set utilizing the width attribute of the <pic:blipFill> component. The worth of the width attribute is laid out in English Metric Items (EMU), the place 1 EMU is the same as 0.001 inch. For instance, to set the width of an image to 1 inch, you’ll use the next code:

<pic:blipFill>
    <a:blip r:embed="rId2"/>
    <a:stretch>
        <a:fillRect/>
        <a:stretchProp>
            <a:fillRect/>
            <a:stretchProp val="1000000"/>
        </a:stretchProp>
    </a:stretch>
</pic:blipFill>

How do I set the side ratio of an image?

The side ratio of an image could be set utilizing the lockAspectRatio attribute of the <pic:stretch> component. When the lockAspectRatio attribute is about to true, the side ratio of the image can be maintained when the image is resized. For instance, to set the side ratio of an image to 16:9, you’ll use the next code:

<pic:blipFill>
    <a:blip r:embed="rId2"/>
    <a:stretch>
        <a:fillRect/>
        <a:stretchProp>
            <a:fillRect/>
            <a:stretchProp val="1000000"/>
        </a:stretchProp>
    </a:stretch>
    <a:lockAspectRatio val="true"/>
</pic:blipFill>

How do I crop an image?

An image could be cropped utilizing the cropLeft, cropTop, cropRight, and cropBottom attributes of the <pic:crop> component. The values of those attributes are laid out in English Metric Items (EMU), the place 1 EMU is the same as 0.001 inch. For instance, to crop an image from the left by 1 inch, you’ll use the next code:

<pic:blipFill>
    <a:blip r:embed="rId2"/>
    <a:stretch>
        <a:fillRect/>
        <a:stretchProp>
            <a:fillRect/>
            <a:stretchProp val="1000000"/>
        </a:stretchProp>
    </a:stretch>
    <pic:crop>
        <pic:cropLeft val="100000"/>
        <pic:cropTop val="0"/>
        <pic:cropRight val="0"/>
        <pic:cropBottom val="0"/>
    </pic:crop>
</pic:blipFill>

How do I rotate an image?

An image could be rotated utilizing the rotation attribute of the <pic:blipFill> component. The worth of the rotation attribute is laid out in levels. For instance, to rotate an image by 90 levels, you’ll use the next code:

<pic:blipFill>
    <a:blip r:embed="rId2"/>
    <a:stretch>
        <a:fillRect/>
        <a:stretchProp>
            <a:fillRect/>
            <a:stretchProp val="1000000"/>
        </a:stretchProp>
    </a:stretch>
    <a:rotation val="900000"/>
</pic:blipFill>

How do I flip an image?

An image could be flipped utilizing the flipH and flipV attributes of the <pic:blipFill> component. The worth of the flipH attribute is about to true to flip the image horizontally, and the worth of the flipV attribute is about to true to flip the image vertically. For instance, to flip an image horizontally, you’ll use the next code:

<pic:blipFill>
    <a:blip r:embed="rId2"/>
    <a:stretch>
        <a:fillRect/>
        <a:stretchProp>
            <a:fillRect/>
            <a:stretchProp val="1000000"/>
        </a:stretchProp>
    </a:stretch>
    <a:flipH val="true"/>
</pic:blipFill>

How do I set the transparency of an image?

The transparency of an image could be set utilizing the alpha attribute of the <pic:blipFill> component. The worth of the alpha attribute is specified as a proportion, the place 0% is totally clear and 100% is totally opaque. For instance, to set the transparency of an image to 50%, you’ll use the next code:

<pic:blipFill>
    <a:blip r:embed="rId2"/>
    <a:stretch>
        <a:fillRect/>
        <a:stretchProp>
            <a:fillRect/>
            <a:stretchProp val="1000000"/>
        </a:stretchProp>
    </a:stretch>
    <a:alpha val="50000"/>
</pic:blipFill>

How do I add a border to an image?

A border could be added to an image utilizing the <pic:border> component. The <pic:border> component has a number of attributes that can be utilized to customise the looks of the border, together with the coloration, width, and dashStyle attributes. For instance, so as to add a 1-point black border to an image, you’ll use the next code:

<pic:blipFill>
    <a:blip r:embed="rId2"/>
    <a:stretch>
        <a:fillRect/>
        <a:stretchProp>
            <a:fillRect/>
            <a:stretchProp val="1000000"/>
        </a:stretchProp>
    </a:stretch>
</pic:blipFill>
<pic:border>
    <pic:coloration rgb="FF000000"/>
    <pic:width val="12700"/>
    <pic:dashStyle val="strong"/>
</pic:border>

How do I group photos?

Photos could be grouped collectively utilizing the <pic:grpSp> component. The <pic:grpSp> component can include a number of <pic:pic> parts, and the images within the group could be organized utilizing the x and y attributes of the <pic:pic> parts. For instance, to group two photos collectively and prepare them facet by facet, you’ll use the next code:

<pic:grpSp>
    <pic:cNvPr id="1" identify="Group 1" descr="Group of two photos"/>
    <pic:cNvGrpSp>
        <a:xfrm>
            <a:off x="0" y="0"/>
            <a:ext cx="0" cy="0"/>
        </a:xfrm>
    </pic:cNvGrpSp>
    <pic:pic>
        <pic:nvPicPr>
            <pic:cNvPr id="2" identify="Image 1" descr=""/>
            <pic:cNvPicPr/>
        </pic:nvPicPr>
        <pic:blipFill>
            <a:blip r:embed="rId2"/>
            <a:stretch>
                <a:fillRect/>
            </a:stretch>
        </pic:blipFill>
        <pic:spPr>
            <a:xfrm>
                <a:off x="0" y="0"/>
                <a:ext cx="0" cy="0"/>
            </a:xfrm>
        </pic:spPr>
    </pic>
    <pic:pic>
        <pic: