Skip to content

Commit a719bc9

Browse files
authored
Merge pull request #11 from saranshs17/main
Script to convert JPEG file into PNG format
2 parents eae37de + e806f55 commit a719bc9

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

JPEG to PNG/Readme.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Add a library reference (import the library) to your Python project.
2+
3+
To add a library reference to your Python project, you can use the `pip` command. For example, to install the Spire.XLS for Python library, you would run the following command:
4+
5+
```sh
6+
pip install Spire.Xls
7+
```
8+
9+
Once the library is installed, you can import it into your Python script using the `import` keyword.

JPEG to PNG/script.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import spire.xls as xls
2+
3+
def convert_jpeg_to_png(input_file_path, output_file_path):
4+
workbook = xls.Workbook()
5+
workbook.LoadFromFile(input_file_path)
6+
7+
# Convert JPEG to PNG by calling Workbook.save() method.
8+
workbook.save(output_file_path, Format=xls.ExcelFormat.PNG)
9+
10+
# Get the conversion result.
11+
conversion_result = workbook.SaveResult
12+
13+
return conversion_result
14+
15+
if __name__ == "__main__":
16+
input_file_path = "input.jpg"
17+
output_file_path = "output.png"
18+
19+
conversion_result = convert_jpeg_to_png(input_file_path, output_file_path)
20+
21+
if conversion_result:
22+
print("The JPEG file was successfully converted to PNG.")
23+
else:
24+
print("An error occurred while converting the JPEG file to PNG.")

0 commit comments

Comments
 (0)