This short tutorial explains how to resize picture in Word using Python. It provides information on environment settings, step-wise program logic, and a runnable sample code to resize image in Word using Python. You will also learn different options to modify images other than changing the size and then saving it in different formats supported by MS Word-like DOCX, DOC, etc.
Steps to Resize Picture in Word using Python
- Establish the environment to add Aspose.Words for Python via .NET to resize images
- Create an empty file using the Document class object for adding images
- Write some sample text wherever required for describing the image
- Insert the image multiple times
- Get a reference to one of the images and set its size
- Save the output file having images of different sizes
These steps summarize the process to resize photo in Word using Python. Simply create a document and instantiate the DocumentBuilder class object having different methods to insert text and images in the linked document. Write some text using the DocumentBuilder.writeln() method and insert one or more images using the DocumentBuilder.insert_image() method followed by setting the size of the added image using the Shape class object.
Code to Resize a Picture in Word using Python
This code demonstrates the process to resize the picture in Word using Python. It uses DocumentBuilder.insert_image() method to insert an image whereas you may use other overloads as well to load an image from a stream, or byte array, insert the image using the file name and set the size right away while adding the image, or even setting the position, and wrap type if required. The ConvertUtil class converts the image size from inches to the points required by the class methods.
In this article, we have learned the process to change picture size in Word using Python. If you want to learn other processes like adding a watermark in a document, refer to the article on how to put a watermark on a Word document using Python.