Description
Creates an image and sets a transparent color.
Returns
Image object
Syntax
imageMakeColorTransparent( img , color__)
History
ColdFusion (2016 release): Use the color parameter as an array of color values.
ColdFusion 10: Added this function
Properties
Parameter |
Description |
|---|---|
img |
Required. The ColdFusion image on which this operation is performed. |
color |
Required. The transparent color:
Multiple transparent colors can be specified using an array. |
Example 1
<cfset myImage=ImageNew("",200,110)>
<!--- Set the drawing color to green. --->
<cfset ImageSetDrawingColor(myImage,"green")>
<!--- Turn on antialiasing to improve image quality. --->
<cfset ImageSetAntialiasing(myImage,"on")>
<!--- Draw a filled green oval on the image. --->
<cfset ImageDrawOval(myImage,5,5,190,100,"yes")>
<!--- Display the image in a browser. --->
<cfoutput>PNG image<br></cfoutput>
<cfset ImageWrite(myImage,"#expandpath('.')#/png.png")>
<cfset myImage = ImageRead("#expandpath('.')#/png.png")>
<cfimage source="#myImage#" action="writeToBrowser" >
<cfset x =ImageMakeColorTransparent(myImage,"green")>
<cfimage source="#x#" action="writeToBrowser" >
Example 2
The sample below uses an array of RGB colors.
<cfscript>
myImage = imageNew("", 200, 200);
myImage = imageMakeColorTransparent(myImage,["255,255,0","123,123,123","0,0,10"]);
cfimage(action="writeToBrowser", source=myImage);
</cfscript>
Example 3
In the code sample below, you can see how arrays of multiple colors are used to make the source image transparent.
<cfscript>
// create array of transparent colors
arrayOfColors=["237,27,36","35,177,77","255,127,38","112,146,191","254,174,201","185,122,87"];
imgObj = imageRead("path/to/image/sample.jpg");
cfimage(action="writeToBrowser", source=imgObj);
img2=ImageMakeColorTransparent(imgObj,arrayOfColors);
cfimage(action="writeToBrowser", source=img2);
</cfscript>
Output
Input image
Output image
Recevez de l’aide plus rapidement et plus facilement
Nouvel utilisateur ?