Resize EPS | JavaScript API Solution
Overview
This article explains how to resize EPS using JavaScript. It covers the following topics.
JavaScript Resize EPS Description
Resizing an image involves adjusting its width and/or height. While the image content remains unchanged, its scale can be altered based on these new dimensions. If you increase both width and height proportionally, the EPS image will appear enlarged; otherwise, it will be smaller. Disproportionate changes to width and height will result in the EPS image being compressed or stretched in a particular direction. Importantly, the EPS file size will remain largely the same, as our solution modifies only the header and setup sections of the EPS file, not its content.
To set a new size for an EPS image, you often need to know its current dimensions and choose the units for the new size. Common units include Points (1/72 of an inch), Inches, Millimeters, Centimeters, and Percents.
So the steps for resizing EPS image in JavaScript follows:
- Create file reader ‘const file_reader = new FileReader();’ and read file ‘file_reader.readAsArrayBuffer(e.target.files[0]);’.
- On load event handler call AsposeResizeEPS and pass the file content and its name, new size as width and height, and unit type to it.
- The result JSON contains the file name in fileNameResult.
- You can download a file by using the DownloadFile function: ‘DownloadFile(JSON.fileNameResult, “image/pdf”);’.
You can check the quality of Aspose.Page EPS Resize and view the results via free online Resize EPS and than view the resulting EPS file with our EPS Viewer
Resize EPS setting new size in Points in JavaScript
In the following JavaScript code snippet new size of the image is set by Points (1/72 of inch):
1 var fResizeEPS = function (e) {
2 const file_reader = new FileReader();
3 file_reader.onload = (event) => {
4 const JSON = AsposeResizeEPS(event.target.result, e.target.files[0].name, e.target.files[0].name + "_resize.eps", 200, 100, Module.Units.Points);
5 if (JSON.errorCode == 0) {
6 DownloadFile(JSON.fileNameResult, "image/eps");
7 }
8 else
9 document.getElementById('output').textContent = JSON.errorText;
10 }
11 file_reader.readAsArrayBuffer(e.target.files[0]);
12 }
Initial image
Resized image
Evaluate resizing EPS online on our Resize EPS web application. You can resize the EPS file and download the result in a few seconds.
You can download examples and data files from
GitHub.