Insert image into PSD layer

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
OlgerD
Posts: 15
Joined: 2015-06-01T21:53:02-07:00
Authentication code: 6789

Insert image into PSD layer

Post by OlgerD »

Hi Guys,

Is there a way to insert an image into a layer in an existing PSD file with IM? Ie, I have a PSD file with 3 layers, and want to insert a jpg into the last layer, without touching the other layers?

Cheers!
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Insert image into PSD layer

Post by snibgo »

Something like this should work. Windows BAT syntax. Adjust for Unix.

Code: Select all

convert ^
  in.psd ^
  ( +clone ^
    in.jpg ^
    -composite ^
  ) ^
  +swap +delete ^
  out.psd
This reads all the layers, makes a clone of the last one, composites x.jpg over it, swaps the last two layers, and deletes the last layer.
snibgo's IM pages: im.snibgo.com
OlgerD
Posts: 15
Joined: 2015-06-01T21:53:02-07:00
Authentication code: 6789

Re: Insert image into PSD layer

Post by OlgerD »

Sweet, I'll give that a try tomorrow. Thanks!
OlgerD
Posts: 15
Joined: 2015-06-01T21:53:02-07:00
Authentication code: 6789

Re: Insert image into PSD layer

Post by OlgerD »

Unfortunately this doesn't quite work. With a 3 layer PSD, it places the image in.jpg onto to topmost layer, instead of the layer I want. I tried using in.psd[1] and even specify the layer name with -label, but none of that worked.
Even if I got it to work as intended, the purpose of this was to leave the other layers as they are, which isn't happening. I had two layers locked in Photoshop, (see another post of mine asking about locking layers) and was hoping this would be another approach to getting layers to stay locked.
IM takes the original PSD, copies all the layers and creates a new PSD. Unfortunately, it doesn't copy layer properties it doesn't know. Which makes sense I suppose.

snibgo wrote:Something like this should work. Windows BAT syntax. Adjust for Unix.

Code: Select all

convert ^
  in.psd ^
  ( +clone ^
    in.jpg ^
    -composite ^
  ) ^
  +swap +delete ^
  out.psd
This reads all the layers, makes a clone of the last one, composites x.jpg over it, swaps the last two layers, and deletes the last layer.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Insert image into PSD layer

Post by fmw42 »

About locking, see viewtopic.php?f=1&t=27740.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Insert image into PSD layer

Post by snibgo »

OlgerD wrote:Unfortunately this doesn't quite work. With a 3 layer PSD, it places the image in.jpg onto to topmost layer, instead of the layer I want.
I don't use Photoshop, and don't know what the "topmost" layer is.

In IM, we can clone any of the images in the list with "-clone N". Then do any processing on that new layer. Then "-swap N,-1", then "+delete".
snibgo's IM pages: im.snibgo.com
OlgerD
Posts: 15
Joined: 2015-06-01T21:53:02-07:00
Authentication code: 6789

Re: Insert image into PSD layer

Post by OlgerD »

fmw42 wrote:About locking, see viewtopic.php?f=1&t=27740.
Yeah, thats my other post I was referring to. :-P
OlgerD
Posts: 15
Joined: 2015-06-01T21:53:02-07:00
Authentication code: 6789

Re: Insert image into PSD layer

Post by OlgerD »

I'm no Photoshop expert either, but I do have access to it at work.
In Photoshop (and I assume this would be true for any app that can open a PSD file), the topmost layer is the highest layer number. Ie, layer 1 is generally the background and in a 3 layer PSD, layer 3 would be the toplayer.
Unfortunately, IM seems to clone only known properties, if any at all.
snibgo wrote:
OlgerD wrote:Unfortunately this doesn't quite work. With a 3 layer PSD, it places the image in.jpg onto to topmost layer, instead of the layer I want.
I don't use Photoshop, and don't know what the "topmost" layer is.

In IM, we can clone any of the images in the list with "-clone N". Then do any processing on that new layer. Then "-swap N,-1", then "+delete".
Post Reply