Components All New MacOS Windows Linux iOS
Examples Mac & Win Server Client Guides Statistic FMM Blog Deprecated Old

GMImage.CopyChannel

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

Component Version macOS Windows Linux Server iOS SDK
GraphicsMagick 7.3 ✅ Yes ✅ Yes ✅ Yes ✅ Yes ✅ Yes
MBS( "GMImage.CopyChannel"; SourceImage; SourceChannel; DestImage; DestChannel )   More

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"; Clip Image::Input ) ]
Set Variable [ $sourceWidth ; Value: MBS( "GMImage.GetWidth"; $SourceImage) ]
Set Variable [ $sourceHeight ; Value: MBS( "GMImage.GetHeight"; $SourceImage) ]
#
# Scale to dest size
Set Variable [ $sourceSize ; Value: If($sourceWidth > $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 > $destHeight; $destHeight; $destWidth) ]
Set Variable [ $tempImage ; Value: MBS( "GMImage.New"; $sourceSize & "x" & $sourceSize; "transparent" ) ]
Set Variable [ $r ; Value: MBS( "GMImage.CompositeXY"; $tempImage; $sourceImage; -($sourceWidth-$sourceSize)/2; -($sourceHeight-$sourceSize)/2; 1) ]
Set Variable [ $r ; Value: MBS( "GMImage.Scale"; $tempImage; $destSize & "x" & $destSize ) ]
#
# Build mask
Set Variable [ $clipImage ; Value: MBS( "GMImage.New"; $destSize & "x" & $destSize; "transparent" ) ]
Set Variable [ $r ; Value: MBS( "GMImage.SetFillColor"; $clipImage; "black" ) ]
Set Variable [ $radius ; Value: $destSize/2 ]
Set Variable [ $r ; Value: MBS( "GMImage.DrawCircle"; $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"; $destWidth & "x" & $destHeight; $gray ) ]
Set Variable [ $r ; Value: MBS( "GMImage.CompositeXY"; $destImage; $tempImage; ($destWidth-$destSize)/2; ($destHeight-$destSize)/2; 1) ]
Set Field [ Clip Image::Output ; MBS( "GMImage.WriteToPNGContainer"; $destImage) ]
#
# Memory cleanup
Set Variable [ $r ; Value: MBS( "GMImage.Release"; $SourceImage) ]
Set Variable [ $r ; Value: MBS( "GMImage.Release"; $tempImage) ]
Set Variable [ $r ; Value: MBS( "GMImage.Release"; $clipImage) ]

See also

Release notes

Example Databases

Blog Entries

This function checks for a license.

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


GMImage.Copy - GMImage.Crop