loonghao / photoshop-python-api

Python API for Photoshop.
https://loonghao.github.io/photoshop-python-api/
MIT License
604 stars 68 forks source link

Issue In Image Placement Even After Setting Image To Same Size As Layer #244

Open chetan-SMRI opened 1 year ago

chetan-SMRI commented 1 year ago

hello i am doing same thing , i tried both of your codes, but in my case i am using exactly same image as layer holder,

when i manually do this in photoshop it works fine(i dont have to do any placement because it is exactly as same pixel as layer), but when i do it through the code, the photo becomes more wider than i thought

code i used --

with Session(mockup, action="open",auto_close=True) as ps:
    active_layer = ps.active_document.activeLayer
    bounds = active_layer.bounds
    # in this segment we are getting the frame of mockup, then we use 
    # our function to adjust the image within given pixel without distortion
    width = int(bounds[2] - bounds[0])
    height = int(bounds[3] - bounds[1])
    adjust_image()# i replace my image here with same width and height as layer
    replace_contents = ps.app.stringIDToTypeID("placedLayerReplaceContents")
    desc = ps.ActionDescriptor
    idnull = ps.app.charIDToTypeID("null")
    desc.putPath(idnull, 'img.png')
    ps.app.executeAction(replace_contents, desc)
    ps.active_document.saveAs(f'res.jpg', ps.JPEGSaveOptions())

i am attaching results for reference - using code - using code manually - manual result mockup file i used - link

Originally posted by @chetan-SMRI in https://github.com/loonghao/photoshop-python-api/issues/38#issuecomment-1507944155

loonghao commented 1 year ago

@chetan-SMRI You need to create a new layer, fill it with content, and convert it to a smart object for easy code replacement

https://user-images.githubusercontent.com/13111745/232515502-eb8f2149-1a5f-4b5b-a9ac-0197c8b24fe8.mp4