composite one image over lots of PSD's

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?".
flieckster
Posts: 11
Joined: 2017-04-26T06:01:35-07:00
Authentication code: 1151

composite one image over lots of PSD's

Post by flieckster »

i have the following script, but i don't seem to understand why its not working. i CD into a directory with hundreds of PSD's and i need to simply over lay that one image and save them back out to a different directory, keeping them as layered PSDs.

when i run it as below, it simply takes the last file in the folder, and coverts it into the MANI.psd file, then gives me this error.

"composite: no decode delegate for this image format `' @ error/constitute.c/ReadImage/509."

Code: Select all

# !/bin/bash 
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
cd /Users/flieckb/Desktop/In/
composite -gravity center /Users/flieckb/Desktop/MANI.psd /Users/flieckb/Desktop/Out/ -format psd "*.psd"
echo "complete"
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: composite one image over lots of PSD's

Post by snibgo »

"composite" needs two input filenames and an output filename. One of your input ends in "Out/" so it is a directory, not a file. Your output filename is "*.psd" which would (if it worked) create a filename called *.psd, which I don't think you want.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: composite one image over lots of PSD's

Post by fmw42 »

Do your two PSD files have multiple layers or just one layer. You can composite the flattened PSD with each other. But I don't think you can composite multi-layer PSD files in ImageMagick.

Code: Select all

composite -gravity center /Users/flieckb/Desktop/MANI.psd /Users/flieckb/Desktop/Out/ -format psd "*.psd"
This syntax does not make sense to me. You have only one input. Composite needs two input images. You have some output directory following the input, but no image with it. That does not work. You also have *.psd at the end. Composite does not allow wildcards as you have used them.
See https://www.imagemagick.org/Usage/compose/

Try

Code: Select all

composite -gravity center image2.psd[0] image2.psd[0] output.psd
or

Code: Select all

convert image1.psd[0] image2.psd[0] -gravity center -compose over -composite out.psd
They put image2 over image1.
flieckster
Posts: 11
Joined: 2017-04-26T06:01:35-07:00
Authentication code: 1151

Re: composite one image over lots of PSD's

Post by flieckster »

Then this won't work if i can't composite on multi layer files. let me see if its easier to just add a text layer.
flieckster
Posts: 11
Joined: 2017-04-26T06:01:35-07:00
Authentication code: 1151

Re: composite one image over lots of PSD's

Post by flieckster »

fmw42 wrote: 2018-09-04T10:01:40-07:00 Do your two PSD files have multiple layers or just one layer. You can composite the flattened PSD with each other. But I don't think you can composite multi-layer PSD files in ImageMagick.

Code: Select all

composite -gravity center /Users/flieckb/Desktop/MANI.psd /Users/flieckb/Desktop/Out/ -format psd "*.psd"
This syntax does not make sense to me. You have only one input. Composite needs two input images. You have some output directory following the input, but no image with it. That does not work. You also have *.psd at the end. Composite does not allow wildcards as you have used them.
See https://www.imagemagick.org/Usage/compose/

Try

Code: Select all

composite -gravity center image2.psd[0] image2.psd[0] output.psd
or

Code: Select all

convert image1.psd[0] image2.psd[0] -gravity center -compose over -composite out.psd
They put image2 over image1.
Fred, can label: be used to create a new layer with text in mulit layer PSDs?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: composite one image over lots of PSD's

Post by fmw42 »

You would need to create the image using label. Then separate all the PSD layers into say PNG files. Then create a new flattened layer from all the layers including the new text image, but without the old flattened layer. Then combine the layers into a new PSD file.

But note, ImageMagick can only handle simple layers. It does not know how to deal with groups or adjustment layers as far as I know. But I will defer to the ImageMagick developers to explain further if I am wrong, since there has been some new developments with PSD files.

Can you post your PSD file to some free hosting service that does not change the format or zip it and then post and then put the URL here, so that I can review your PSD file. Also what version of ImageMagick and platform are you using? If on Linux, then provide the ImageMagick version with date.

Code: Select all

convert -version
flieckster
Posts: 11
Joined: 2017-04-26T06:01:35-07:00
Authentication code: 1151

Re: composite one image over lots of PSD's

Post by flieckster »

Hi fred, here's some sample PSD's. i read more into it, i wonder if -draw is a better option to simply put a visual marker in my PSD files. its just something so retouchers don't grab these while they are out with someone getting retouched.

here is a wetrasnefer of files to view. https://we.tl/t-b7uL9JJNGl

Code: Select all

Version: ImageMagick 7.0.5-5 Q16 x86_64 2017-04-25 http://www.imagemagick.org
Copyright: © 1999-2017 ImageMagick Studio LLC
License: http://www.imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules 
Delegates (built-in): bzlib freetype jng jpeg ltdl lzma png tiff xml zlib
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: composite one image over lots of PSD's

Post by fmw42 »

Try these two commands. The first imbeds the text into each image. The second seems to add a new layer of the text on a transparent background.

Code: Select all

magick UNIQ-118F001A_69_C1.psd -coalesce \
-gravity south -pointsize 300 -fill red -annotate +0+20 "TESTING" \
test.psd

Code: Select all

magick UNIQ-118F001A_69_C1.psd \
\( -clone 0 -alpha transparent -gravity south -pointsize 300 \
-fill red -annotate +0+20 "TESTING" \) \
-adjoin test2.psd
Do either do what you need?
flieckster
Posts: 11
Joined: 2017-04-26T06:01:35-07:00
Authentication code: 1151

Re: composite one image over lots of PSD's

Post by flieckster »

Hi Fred, the 2nd works well. is this something i can batch a whole directory of files out as some side shell script by telling image magick where images will be, and where i want them placed?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: composite one image over lots of PSD's

Post by fmw42 »

For the second command, you would have to write a script loop over each file in a given directory and then output to another empty existing directory. What is your platform? Unix or Windows?

If on Unix (Linux or Mac), then try the following. Folder1 has your images and is on my desktop. Folder 2 is empty, but already created.

Code: Select all

cd
cd desktop/folder1
list=`ls | egrep ".psd"`
for img in $list; do
echo "$img"
magick $img \
\( -clone 0 -alpha transparent -gravity south -pointsize 300 -fill red -annotate +0+20 "TESTING" \) \
../folder2/$img
done
The first command could be done using mogrify on a whole directory. See https://www.imagemagick.org/Usage/basics/#mogrify
flieckster
Posts: 11
Joined: 2017-04-26T06:01:35-07:00
Authentication code: 1151

Re: composite one image over lots of PSD's

Post by flieckster »

Thanks this is a great working start, the only issue i see is that the changes aren't visible in bridge or in preview, so you can't see any update till you open the image. How do you get IM to regenerate the thumbnails?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: composite one image over lots of PSD's

Post by fmw42 »

This will fix that by recreating the flattened layer to include the new text layer.

Code: Select all

magick UNIQ-118F001A_69_C1.psd \
\( -clone 0 -alpha transparent -gravity south -pointsize 300 \
-fill red -annotate +0+20 "TESTING" \) \
\( -clone 1--1 -flatten \) \
-swap 0,-1 +delete \
test2.psd
flieckster
Posts: 11
Joined: 2017-04-26T06:01:35-07:00
Authentication code: 1151

Re: composite one image over lots of PSD's

Post by flieckster »

Thanks Fred.

i ended up playing i little to get here, to add a little layer overlay to help make it clear

Code: Select all

magick $img \
\( -clone 0 -alpha off -fill black -colorize 75% \) \
\( -clone 0 -alpha transparent -gravity center -pointsize 900 \
-fill red -annotate +0+20 "MANI" \) \
\( -clone 1--1 -flatten \) \
-swap 0,-1 +delete \
i noticed that when i run this, it removes any color profile from the files, what can i do to keep that color profile?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: composite one image over lots of PSD's

Post by snibgo »

It shouldn't remove colour profiles. It doesn't for me, with IM v7.0.7-28, writing to TIFF. I know nothing about PSD files.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: composite one image over lots of PSD's

Post by fmw42 »

Yes, for me all the photoshop meta data is lost as well as the color profile. This is likely because I recreated the flattened layer. But I cannot say for sure. The only way to handle that is to extract the profile from the original image first, then put it back at the end.

Code: Select all

magick UNIQ-118F001A_69_C1.psd[0] profile.icc
magick UNIQ-118F001A_69_C1.psd \
\( -clone 0 -alpha transparent -gravity south -pointsize 300 \
-fill red -annotate +0+20 "TESTING" \) \
\( -clone 1--1 -flatten \) \
-swap 0,-1 +delete -profile profile.icc \
test2.psd
or

Code: Select all

magick UNIQ-118F001A_69_C1.psd \
\( -clone 0 +write profile.icc +delete \) \
\( -clone 0 -alpha transparent -gravity south -pointsize 300 \
-fill red -annotate +0+20 "TESTING" \) \
\( -clone 1--1 -flatten \) \
-swap 0,-1 +delete -profile profile.icc \
test2.psd

If you want to composite two PSD files with the same number of layers, then you could separate the layers into PNG files. The composite each pair of PNG files. Then regenerate the PSD file from each of the composited layers.
Post Reply