Topics   All   Mac OS X (Only)   Windows (Only)   Linux (Only, Not)   iOS (Only, Not)  
Components   Crossplatform Mac & Win   Server (Not)   Client   Old   Guides   Examples
New in version: 6.1   6.2   6.3   6.4   6.5   7.0   7.1   7.2   7.3   7.4    Statistic  

GMImage.CopyChannel

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

Component Version macOS Windows Server FileMaker Cloud FileMaker iOS SDK
GraphicsMagick 7.3 Yes Yes Yes Yes Yes

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

Parameters

Parameter Description Example value
DestImage The image reference number of dest image. $destImage
DestChannel The dest channel.
Can be Red, Green, Blue or Opacity.
"Opacity"
SourceImage The image reference number of source image. $sourceImage
SourceChannel The source 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.Destroy"; $SourceImage) ]
Set Variable [ $r ; Value: MBS( "GMImage.Destroy"; $tempImage) ]
Set Variable [ $r ; Value: MBS( "GMImage.Destroy"; $clipImage) ]

See also


GMImage.Copy   -   GMImage.Crop

Feedback: Report problem or ask question.




Links
MBS Xojo PDF Plugins