Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 11031f4

Browse files
PSD To Image File Script added
1 parent 1472d61 commit 11031f4

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

‎PSD To Image/README.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# PSD To JPEG,PNG Script
2+
The script can convert the PSD to JPEG, PNG file
3+
4+
What the program does?
5+
- Can accepts single, multiple files
6+
- Convert PSD to JPEG, PNG
7+
- Single operation at a time
8+
9+
### Requirements
10+
> Python3
11+
>
12+
> pip install -r requirements.txt
13+
14+
### Usage
15+
```
16+
psd2png.py [-h] -f FILE [FILE ...] [-j] [-p]
17+
18+
Convert PSD to JPEG, PNG
19+
20+
optional arguments:
21+
-h, --help show this help message and exit
22+
-f FILE [FILE ...] Submit a PSD file(s)
23+
-j Convert PSD to JPEG
24+
-p Convert PSD to PNG
25+
```
26+
27+
### Contribution
28+
Any kind of contributions are welcome.
29+
30+
1. Fork the Project
31+
2. Commit your Changes
32+
3. Open a Pull Request

‎PSD To Image/psd2png.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import argparse
2+
import os
3+
4+
from psd_tools import PSDImage
5+
6+
7+
def pngCreator(files, img_extension):
8+
for file in files:
9+
10+
# Iterate through the files
11+
if os.path.isfile(f'{os.getcwd()}\{file}'):
12+
13+
# Get the base filename
14+
filename_full = os.path.basename(file)
15+
16+
# Get the filename and extension
17+
filename, extension = os.path.splitext(filename_full)
18+
19+
# Check the extension of file is psd
20+
if extension == '.psd':
21+
22+
# Open the file
23+
psd = PSDImage.open(file)
24+
25+
# Save the file according to extension provided
26+
psd.composite().save(f'{filename}.{img_extension}')
27+
28+
print(f'File created: {filename}.{img_extension}')
29+
30+
else:
31+
print(f'Extension NOT Valid for file: {file}')
32+
33+
34+
def main():
35+
parser = argparse.ArgumentParser(description='Convert PSD to JPEG, PNG')
36+
37+
# Argument is to accept a file(s)
38+
parser.add_argument('-f', dest='file', nargs='+', type=str, help='Submit a PSD file(s)', required=True)
39+
40+
# Argument is to convert psd file to jpeg
41+
parser.add_argument('-j', dest='jpeg', action='store_true', help='Convert PSD to JPEG')
42+
43+
# Argument is to convert psd file to png
44+
parser.add_argument('-p', dest='png', action='store_true', help='Convert PSD to PNG')
45+
46+
args = parser.parse_args()
47+
48+
if args.file:
49+
# Accepts files
50+
files = args.file
51+
52+
# JPEG parameter is selected
53+
if args.jpeg:
54+
pngCreator(files, 'jpeg')
55+
56+
# PNG parameter is selected
57+
elif args.png:
58+
pngCreator(files, 'png')
59+
60+
else:
61+
print('See Help: psd2png.py -h')
62+
63+
else:
64+
print('No Files Given')
65+
66+
67+
if __name__ == '__main__':
68+
main()

‎PSD To Image/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
psd_tools==1.9.17

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /