Merge two image files color and alpha into one

Hello, can anyone give me a point to start with this script?

I have a bunch of images and in a separate file the alpha layer of each image, named the same but with the _a prefix,.I am trying to merge that two images into a single one with the alpha channel included.

Could I do this with preview or I need photoshop?

Thanks

Preview can’t do it, nor can Image Events. But iMagine Photo can. Though how you do it in iMagine Photo will depend on more details. iMagine Photo is free.

When you say the alpha channel is included in another file. Does that mean the other file contains a greyscale image that is the transparency information, or does it contain an image with an alpha channel that you then want to add to your image without an alpha channel?

Are the dimensions in pixels of the image and the alpha layer the same?
What sort of image files are you storing the data in.
Photoshop, tiff, png, jpg etc?
What is the output image format?

Kevin

Use the duplicate command, example below

tell application "Adobe Photoshop CS"
	set x to document 1
	set y to document 2
	set z to count of channels of x
	set current document to x
	duplicate channel 5 of x to y
end tell

Thanks you two! :slight_smile:

The files are the same size and the alpha ones contains a graylevel image with the alpha information
I never use imaginePhoto, I am going to check it and also try the “duplicate” way for Photoshop
Thanks a lot!

The duplicate operation works fine. thanks

now I am triyng to load the alpha image when I drop the image, the alpha image is in the same folder and ends with _a but when I try to modify the path I got in troubles

The code below doesnt work because add the _a sufix after the .jpg extension, any ideas?
thanks


on open these_items
	tell application "Finder"
		repeat with i from 1 to the count of these_items
			set this_item to (item i of these_items)
			set alphapath to (((this_item) as text) & "_a")
			copy alphapath as alias to filePath
			--open indesign and save as indesign
			tell application "Adobe Photoshop CS2"
				open this_item
				open filePath
				-- set x to document 1 the image
				-- set y to document 2 the alpha channel
				-- set current document to y
				-- duplicate channel 2 of y to x
			end tell
			set label index of this_item to 5
		end repeat
	end tell
end open

Hello again, I am doing my homework, now I can extract the path info and add the sufix _a.jpg, now I think I have the path for my alpha file but Photoshop doesnt open anything.

I am pretty newbie in applescript, could anyone help me, please?

Thanks for your time


on open these_items
	tell application "Finder"
		repeat with i from 1 to the count of these_items
			set this_item to (item i of these_items)
			set passvariable1 to ((this_item) as string)
			set passvariable2 to count passvariable1
			set passvariable3 to text from beginning to character (passvariable2 - 4) of passvariable1
			set alphapath to passvariable3 & "_a.jpg"
			--open indesign and save as indesign
			tell application "Adobe Photoshop CS2"
				open alphapath
				-- set x to document 1 the image
				-- set y to document 2 the alpha channel
				-- set current document to y
				-- duplicate channel 2 of y to x
			end tell
			set label index of this_item to 5
		end repeat
	end tell
end open

You say that the alpha image has an _a added ie “imagename_a.jpg”. If this is the case why add the _a using applescript?

The reason the script won’t open the file is that Photoshop requires the complete adrress as alias. ie

alias “yourdiskr:Users:you:Desktop:yourfolder:imagename_a.jpg”

your script only uses the name

just coerce the variable to an alias:

open alias alphapath

Thanks!!
Now works fine, It is a very rough script by now, but it works!!
I dont understand well how to work with files yet :frowning:

Thank you again

I found very useful this book to start to learn applescript, maybe could help someone else.

http://www.wrox.com/WileyCDA/WroxTitle/productCd-0764574000.html

weedinner, the variable alphapath is the complete path to the alpha image file, the problem was that i didnt coerce as a alias variable, I use this way to process a lot of files -using the script as a drag n drop app- because is the only way that I know yet.

It is really nice for me to learn applescript it has a soft learning curve and in a few days you can start to write useful scripts