Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to import Images into Document #340

Open
DEV-Devound opened this issue May 6, 2024 · 0 comments
Open

How to import Images into Document #340

DEV-Devound opened this issue May 6, 2024 · 0 comments

Comments

@DEV-Devound
Copy link

How can i complete this
# Make it import the profile image into the PSD file # Import the profile image as a new layer part of my code? I've tried with what the Docs say but when i try to implement it into my code it justs bugs

FULL CODE HERE:

`from flask import Flask, request, send_from_directory
from werkzeug.utils import secure_filename
import photoshop.api as ps
import os

app = Flask(name, static_url_path='')

@app.route('/')
def index():
return send_from_directory('.', 'index.html')

@app.route('/write', methods=['POST'])
def write():
first_name = request.form['first_name']
last_name = request.form['last_name']
psd_file = request.files['psd_file']
profile_image = request.files['profile_image']

psd_file_path = os.path.abspath(secure_filename(psd_file.filename))
profile_image_path = os.path.abspath(secure_filename(profile_image.filename))

psd_file.save(psd_file_path)
profile_image.save(profile_image_path)

# Load the PSD file
doc = ps.Application().open(psd_file_path)

# Edit the text layers called first_name and last_name (replace their text to the ones from the request.form)
for layer in doc.layers:
    if layer.kind == ps.LayerKind.TextLayer:
        if layer.name == 'first_name':
            layer.textItem.contents = first_name
        elif layer.name == 'last_name':
            layer.textItem.contents = last_name

print("Input are: " + first_name + " " + last_name)

# Make it import the profile image into the PSD file
# Import the profile image as a new layer


# Save the document as a new JPG file
new_jpg_file = 'new_' + os.path.splitext(psd_file.filename)[0] + '.jpg'
doc.saveAs(new_jpg_file, options=ps.JPEGSaveOptions(quality=12), asCopy=True)

return 'File has been written with the name ' + new_jpg_file

if name == 'main':
app.run(port=3000)
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant