GMImage.CopyChannel
-------------------

Copies one channel from one image into channel of other image.

| Component | Version | macOS | Windows | Linux | Server | iOS SDK |
|---|---|---|---|---|---|---|
| [GraphicsMagick](component_GraphicsMagick.md) | [7.3](newinversion73.md) | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |

MBS( "GMImage.CopyChannel"; SourceImage; SourceChannel; DestImage; DestChannel ) 

**MBS**( **"GMImage.CopyChannel";** /\* Copies one channel from one image into channel of other image. \*/  
**$SourceImage**; /\* The image reference number of source image. \*/   
**$SourceChannel**; /\* The source channel.  
Can be Red, Green, Blue or Opacity.e.g. "Opacity" \*/   
**$DestImage**; /\* The image reference number of dest image. \*/   
**$DestChannel**) /\* The dest channel.  
Can be Red, Green, Blue or Opacity.e.g. "Opacity" \*/ 

### Parameters

| Parameter | Description | Example |
|---|---|---|
| SourceImage | The image reference number of source image. | $sourceImage |
| SourceChannel | The source channel.   Can be Red, Green, Blue or Opacity. | "Opacity" |
| DestImage | The image reference number of dest image. | $destImage |
| DestChannel | The dest channel.   Can be Red, Green, Blue or Opacity. | "Opacity" |

### Result

Returns OK or error.

### Description

Copies one channel from one image into channel of other image.  
e.g. to copy opacity from one image to other.  
### Examples

Clip an image:

 Set Variable \[ $gray ; Value: "#777777" \]   
\# Read in source image   
Set Variable \[ $SourceImage ; Value: MBS ( "[GMImage.NewFromContainer](GMImageNewFromContainer.md)"; Clip Image::Input ) \]   
Set Variable \[ $sourceWidth ; Value: MBS ( "[GMImage.GetWidth](GMImageGetWidth.md)"; $SourceImage ) \]   
Set Variable \[ $sourceHeight ; Value: MBS ( "[GMImage.GetHeight](GMImageGetHeight.md)"; $SourceImage ) \]   
\#   
\# Scale to dest size   
Set Variable \[ $sourceSize ; Value: If($sourceWidth &gt; $sourceHeight ; $sourceHeight ; $sourceWidth ) \]   
Set Variable \[ $destWidth ; Value: GetAsNumber ( Clip Image::Width ) \]   
Set Variable \[ $destHeight ; Value: GetAsNumber ( Clip Image::Height ) \]   
Set Variable \[ $destSize ; Value: If($destWidth &gt; $destHeight ; $destHeight ; $destWidth ) \]   
Set Variable \[ $tempImage ; Value: MBS ( "[GMImage.New](GMImageNew.md)"; $sourceSize &amp; "x" &amp; $sourceSize ; "transparent" ) \]   
Set Variable \[ $r ; Value: MBS ( "[GMImage.CompositeXY](GMImageCompositeXY.md)"; $tempImage ; $sourceImage ; -($sourceWidth -$sourceSize )/2; -($sourceHeight -$sourceSize )/2; 1) \]   
Set Variable \[ $r ; Value: MBS ( "[GMImage.Scale](GMImageScale.md)"; $tempImage ; $destSize &amp; "x" &amp; $destSize ) \]   
\#   
\# Build mask   
Set Variable \[ $clipImage ; Value: MBS ( "[GMImage.New](GMImageNew.md)"; $destSize &amp; "x" &amp; $destSize ; "transparent" ) \]   
Set Variable \[ $r ; Value: MBS ( "[GMImage.SetFillColor](GMImageSetFillColor.md)"; $clipImage ; "black" ) \]   
Set Variable \[ $radius ; Value: $destSize /2 \]   
Set Variable \[ $r ; Value: MBS ( "[GMImage.DrawCircle](GMImageDrawCircle.md)"; $clipImage ; $radius ; $radius ; 0; $radius ) \]   
\#   
\# Apply mask   
Set Variable \[ $r ; Value: MBS ( "GMImage.CopyChannel"; $tempImage ; "Opacity"; $clipImage ; "Opacity") \]   
\#   
\# Create destination image   
Set Variable \[ $destImage ; Value: MBS ( "[GMImage.New](GMImageNew.md)"; $destWidth &amp; "x" &amp; $destHeight ; $gray ) \]   
Set Variable \[ $r ; Value: MBS ( "[GMImage.CompositeXY](GMImageCompositeXY.md)"; $destImage ; $tempImage ; ($destWidth -$destSize )/2; ($destHeight -$destSize )/2; 1) \]   
Set Field \[ Clip Image::Output ; MBS ( "[GMImage.WriteToPNGContainer](GMImageWriteToPNGContainer.md)"; $destImage ) \]   
\#   
\# Memory cleanup   
Set Variable \[ $r ; Value: MBS ( "[GMImage.Release](GMImageRelease.md)"; $SourceImage ) \]   
Set Variable \[ $r ; Value: MBS ( "[GMImage.Release](GMImageRelease.md)"; $tempImage ) \]   
Set Variable \[ $r ; Value: MBS ( "[GMImage.Release](GMImageRelease.md)"; $clipImage ) \]  
### See also

- [GMImage.BlurChannel](GMImageBlurChannel.md)
- [GMImage.DrawCircle](GMImageDrawCircle.md)
- [GMImage.GetHeight](GMImageGetHeight.md)
- [GMImage.GetWidth](GMImageGetWidth.md)
- [GMImage.LevelChannel](GMImageLevelChannel.md)
- [GMImage.New](GMImageNew.md)
- [GMImage.NewFromContainer](GMImageNewFromContainer.md)
- [GMImage.Scale](GMImageScale.md)
- [GMImage.SetFillColor](GMImageSetFillColor.md)
- [GMImage.WriteToPNGContainer](GMImageWriteToPNGContainer.md)

### Release notes

- **Version 8.4**
    - Improved performance for [GMImage.CopyChannel](http://www.mbsplugins.eu/GMImageCopyChannel.shtml) when copying within the same image.
- **Version 8.2**
    - Fixed bug in [GMImage.CopyChannel](http://www.mbsplugins.eu/GMImageCopyChannel.shtml) function.
- **Version 7.3**
    - Added [GMImage.CopyChannel](http://www.mbsplugins.eu/GMImageCopyChannel.shtml) function.

### Example Databases

- [GraphicsMagick/Clip Image](https://www.mbsplugins.eu/MBS-FileMaker-Plugin-Examples/GraphicsMagick/Clip%20Image.shtml#1ScriptAnchor_)

### Blog Entries

- [MBS FileMaker Plugin, version 8.4pr1](https://www.mbsplugins.de/archive/2018-08-01/MBS_FileMaker_Plugin_version_8/monkeybreadsoftware_blog_filemaker)
- [MBS FileMaker Plugin, version 8.2pr2](https://www.mbsplugins.de/archive/2018-04-11/MBS_FileMaker_Plugin_version_8/monkeybreadsoftware_blog_filemaker)
- [Circle crop images in FileMaker with MBS Plugin](https://www.mbsplugins.de/archive/2018-01-18/Circle_crop_images_in_FileMake/monkeybreadsoftware_blog_filemaker)

### FileMaker Magazin

- [Ausgabe 6/2020, Seite 38](https://filemaker-magazin.de/neuigkeit/4118-Appetithappen-FMM_202006)

This function checks for a license.

Created 16th July 2017 , last changed 21st December 2018

  
[GMImage.Copy](GMImageCopy.md) - [GMImage.Crop](GMImageCrop.md)

[HTML Version](GMImageCopyChannel.shtml)