adds text to an image.
A structure containing the following fields:
| key | value |
|---|---|
| errorCode | 0 for success, non-zero for failure. Always returned, but not really used if the throwOnError option is set to true. |
| errorMessage | A description of the error. Always returned, but not really used if the throwOnError option is set to true. |
| img | A java BufferedImage object is returned if no output file is specified |
addText(objImage,inputFile,outputFile,x,y,fontDetails,content,jpegCompression)
| Parameter | Required? | Default | Description |
|---|---|---|---|
| objImage | YES | - | A java image object, or a blank string. |
| inputFile | YES | - | File path or URL to an image, or a blank string. |
| outputFile | YES | - | File path to write the output, or a blank string. |
| x | YES | - | X coordinate where the text is to be placed. |
| y | YES | - | Y coordinate where the text is to be placed. |
| fontDetails | YES | - |
A struct containing font information, containing these keys:
|
| content | YES | - | The string to be added to the image. |
| jpegCompression | NO | defaultJpegCompression | jpeg compression quality to use if writing a jpeg file. 0-100. 100 is the highest quality. |
You must supply either an image object or a file path to a source image.
<cfset imageCFC = createObject("component","image")>
<cfset fontDetails = StructNew()>
<cfset fontDetails.fontName = "Serif">
<cfset fontDetails.style = "font.BOLD">
<cfset fontDetails.color = "maroon">
<cfset fontDetails.size = 20>
<cfset results = imageCFC.addtext("", "#ExpandPath(".")#/myimage.jpg", "#ExpandPath(".")#/myimage2.jpg", 10, 10, fontDetails, "Sample Text")>
When you use the addText() method with a truetype font file, you will find that java creates temp files somewhere on your system. In the Linux world, it seems to be /tmp and the files are named JF*.tmp
These don't get cleaned up!!! You'll need to write some kind of script to clean them up manually. For example, I use this as a cron job:
* * * * * /usr/bin/find /tmp -cmin +2 -name \*JF\*.tmp | /usr/bin/xargs /bin/rm
For further discussion, see this thread in the imageCFC forums: