Resize and crop EPS file

Manage size of EPS images. Unlock a world of possibilities whether you’re building desktop applications, web platforms, or console utilities with Aspose.Page native API Solution for Python.

 

Harness the capabilities of our Python API Solution to seamlessly crop and resize EPS files. Our simple technology empowers you to precisely trim and refine your visuals, adjusting margins to achieve the perfect image. The resulting EPS image is consistently captivating, with the added benefit of maintaining your file size unchanged.

Resizing EPS files may be necessary for several reasons:

  • EPS files may need to be resized to fit specific dimensions or scale requirements for printing or display purposes, for example, if an EPS image needs to fit within a certain space on a webpage or in a document.

  • Resizing EPS files can help reduce their file size hence optimizing storage space and improving loading times.

  • EPS files may need to be resized to adjust their resolution.

  • Resizing EPS files can help correct the aspect ratio if the original image appears stretched or squished.

  • Some applications or platforms may have size limitations or requirements for EPS files. Resizing the files to meet these specifications ensures compatibility with the intended software or platform.

Cropping an image is a precise operation that trims the image's margins – left, right, top, and bottom – removing excess content at the edges. This results in a more compact EPS image, always smaller than the original. Notably, our solution keeps the file size unchanged by focusing exclusively on the EPS file header, leaving your content intact. The EPS image's margins are determined by the BoundingBox metadata. To redefine these margins and establish a new bounding box, it's crucial to know the existing bounding box of the EPS image. This ensures error-free cropping and a flawless outcome.

To resize or crop EPS first get:

  • Aspose.Page for Python API which is a feature-rich, powerful, and easy-to-use document manipulation and conversion API for the Python platform.

  • Get the latest version of Aspose.Page for Python from pypi.org or Aspose.Releases .

Console Command


    >pip install aspose-page

Steps to cut EPS image in Python.

The example below shows the getting rid of white margins from .eps with the chosen units - points. The order is:

  1. Initialize the PsDocument object with an input stream containing an EPS file.
  2. Define the existing bounding box of the image using the extract_eps_bounding_box() static method.
  3. Create an output stream for the resulting EPS file.
  4. Create a new bounding box.
  5. Cut off the needless borders of EPS file with a new bounding box using the crop_eps() static method.
  6. Save the result file.

Python Code to crop EPS images.

	from aspose.page.eps import *
	from util import Util
	
	# The path to the documents directory.
	data_dir = Util.get_data_dir_working_with_eps()
	
	#Create an input stream for EPS file
	input_eps_stream = open(data_dir + "input.eps")
	#Initialize PsDocument object with input stream
	doc = PsDocument(input_eps_stream)
	
	#Get initial bounding box of EPS image
	initial_bounding_box = doc.extract_eps_bounding_box()
	
	#Create an output stream for resized EPS
	output_eps_stream = open(data_dir + "output_crop.eps")
	#Create new bounding box
	#Bounding box is represented by 4 numbers: x0, y0, x, y, where x0 - left margin, y0 - top margin, x - (x0 + width), y - (y0 + height)
	new_bounding_box = [ 260, 300, 480, 432 ]
	
	#Crop EPS image and save to the output stream                    
	#Croping of image is changing of its bounding box so that new values of bounding box will be within initial bounding box, that is
	#initialBoundingBox[0] <= newBoundingBox[0] <= initialBoundingBox[2]
	#initialBoundingBox[1] <= newBoundingBox[1] <= initialBoundingBox[3]
	#initialBoundingBox[0] <= newBoundingBox[2] <= initialBoundingBox[2]
	#initialBoundingBox[1] <= newBoundingBox[3] <= initialBoundingBox[3]
	doc.crop_eps(output_eps_stream, new_bounding_box)



FAQ

1. Is it possible to change the size of EPS files?

EPS files are essentially PostScript files encapsulated within a bounding box, and they can be resized by modifying the bounding box parameters to specify the desired region of the image. This process effectively trims away any unwanted areas of the EPS image or make them bigger.

2. How can I resize an Encapsulated PostScript file?

Aspose.Page lets you set a new size for EPS files using the ExtractEpsSize() static Method to get the size of the actual file and resize it with a new size in points with the ResizeEps() static Method.

3. Are there any tools or software specifically designed for changing the size of EPS (Encapsulated PostScript) files?

Aspose.Page has EPS Resize cross-platform application that lets you resize files online in just a second.

EPS What is EPS File Format

EPS (EPSF) or Encapsulated PostScript File Format is the format that is actually a PS program that describes what would a single page look like. It is actually limited PS plus particular notes that help encapsulate PostScript graphics to another document. EPS perfectly supports vector graphics or combined vector-raster graphics. The peculiarity of the format is that as soon as it is imported into a document, it cannot be edited anymore. That is one of the reasons to convert this format to the one you are able to work with.