• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

ImageWrite ram destination best practise?

New Here ,
Mar 30, 2020 Mar 30, 2020

Copy link to clipboard

Copied

Hi,
Im including a barcode in a email, within a  cfloop:

<cfset myImage=ImageNew("",200,70,"grayscale","white")>
<cfset attr = StructNew()>
<cfset attr.font="Archon Code 39 Barcode">
<cfset attr.size=50>
<cfset ImageSetDrawingColor(myImage,"black")>
<cfset ImageAddBorder(myImage,1,"black")>
<cfset ImageDrawText(myImage,"*#email.unique_id#*",15,50,attr)>
<cfset ImageWrite(myImage, "ram:///barcode#email.unique_id#.jpg", 1, "true")>
 
within cfmail tag:
 
<img src="cid:Barcode#email.unique_id#" width="200" height="70" alt="#email.unique_id# Barcode" />
<cfmailparam file="ram:///barcode#email.unique_id#.jpg"
contentid="Barcode#email.unique_id#"
disposition="inline" />
 
The image is re-created each loop, but I had to give it a unique name per loop as the image never changed in the email.
 
Do you have to "dispose" of the image each loop?
Do I have to delete the image of out RAM ?
Any extra tips you have\best practice?
Thanks,
 

Views

1.4K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 31, 2020 Mar 31, 2020

Copy link to clipboard

Copied

Hello, Scott,

 

I'm not sure that I fully understand your query, but I'll give it a shot.

 

From what I've read (and I'm going to re-read it before continuing), is this image unique per email, as in the barcode will change depending upon who it's going to?  Or is the barcode static and you're just creating a new image of the same barcode that everyone will receive?

 

If the former, then you _should_ be able to use the same filename.  I cannot think of any reason why CF would force you to use a unique name.

 

If the latter, then you don't need to do this _inside_ the loop.  You can create it before the loop and use the same filename in each email (much less CPU intensive; and less RAM write/reads.)

 

HTH,

 

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 31, 2020 Mar 31, 2020

Copy link to clipboard

Copied

FOLLOW UP:

 

Yes, I would recommend deleting the file when you are done, as the RAM will keep those images for as long as the server is powered on.  Since you have the overwrite attribute set to TRUE, then you're not going to fill-to-overflow the RAM space, but those files disappear by only two methods I am aware of: manually deleting them, or power down / reboot the server.

 

V/r,

 

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 31, 2020 Mar 31, 2020

Copy link to clipboard

Copied

HI,

 

How do you delete the file from RAM? I've been looking for examples, but haven't found any.

 

To further show what I am experiencing, the following code sends to me ( viewed via Outlook ), 3 emails, BUT each have a barcode from index 3 ( not 1,2, and 3)

<CFLOOP from="1" to="3" index="loopindex">

<!--- 
Create Bar Code
--->
<cfset myImage=ImageNew("",200,70,"grayscale","white")> 
<cfset attr = StructNew()> 
<cfset attr.font="Archon Code 39 Barcode"> 
<cfset attr.size=50> 
<cfset ImageSetDrawingColor(myImage,"black")> 
<cfset ImageAddBorder(myImage,1,"black")> 
<cfset ImageDrawText(myImage,"*Index #loopindex# *",15,50,attr)>
<cfset ImageWrite(myImage, "ram:///barcode.jpg", 1, "true")>

<cfmail from="myemail@domain.au" to="myemail@domain.au" subject="Index #loopindex#" type="html">
This email should have a Barcode for Index #loopindex#<br>
<img src="cid:Barcode#loopindex#" width="200" height="70" alt="#loopindex# Barcode" />
<cfmailparam file="ram:///barcode.jpg"
contentid="Barcode#loopindex#"
disposition="inline" /> 

</cfmail>

</CFLOOP>

I thought it might have been due to the fact that the <img src ... > wasn't unique and that the contentid of the cfmailparam wasn't unique, but it is now, and the problem still occurs.

 

cf 2016

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 01, 2020 Apr 01, 2020

Copy link to clipboard

Copied

I'm really not understanding what you are attempting to do.

 

Is each email to contain a unique barcode?  Or is each email to have the same barcode image?

 

I'm further confused by the fact that you are including HTML <img /> tag in the body of the email, but then you are also using a CFMAILPARAM to attach a file.

 

Why?

 

And the <img /> tag src is a cid, which is ancient (think Outlook), doesn't work in all email clients, and makes the email larger than it needs to be.  CFMAILPARAM is the only thing you need to do, unless you want the image inline instead of as an attachment.  Which is okay, lots of organizations send newsletters in HTML format to appear pleasing to the user receiving it.  But the examples you are providing don't look like HTML formatted content.

 

V/r,

 

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 01, 2020 Apr 01, 2020

Copy link to clipboard

Copied

I'm really not understanding what you are attempting to do.

Send a unique bar code in an email.

Is each email to contain a unique barcode?  Or is each email to have the same barcode image?

Yes, each email is to have a unique barcode

I'm further confused by the fact that you are including HTML <img /> tag in the body of the email, but then you are also using a CFMAILPARAM to attach a file.

Its a HTML email, thats how you do it to include the image in the HTML instead of an attachment.

Why?

Why what? Response's to the email are printed as a PDF, saved to a directory, and other software reads the barcode and attaches the PDF to a record.

And the <img /> tag src is a cid, which is ancient (think Outlook), doesn't work in all email clients, and makes the email larger than it needs to be.  CFMAILPARAM is the only thing you need to do, unless you want the image inline instead of as an attachment.  Which is okay, lots of organizations send newsletters in HTML format to appear pleasing to the user receiving it.  But the examples you are providing don't look like HTML formatted content.

Yes, thats how it works. The example is much reduced, suffice to say its a html email, the entire contents aren't germain to the unique barcode.

 

At any rate, including a 

 

<cffile action="delete" file="ram:///barcode.jpg">

 

deletes the image, and is the answer to my question, but then the problem arises that the image is deleted prior to the email spool\process sending the email such the file does not exist and causes an error, but I can work around that.

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 02, 2020 Apr 02, 2020

Copy link to clipboard

Copied

I'm jumping into the end of this thread without reading it all. But my recommendation is to use unique names using UUIDs, and not bother deleting the images from RAM (or the disk or wherever you might store them in the future) as part of the individual process generating each email. Have a cleanup process that runs after the fact, that deletes them after all the emails have been sent.

 

Dave Watts, Eidolon LLC

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 02, 2020 Apr 02, 2020

Copy link to clipboard

Copied

As Dave has mentioned, you can always use a clean-up process at midnight or 2am.

 

Or, you can create an array and fill it with filenames in your loop, then iterate that and delete the files after the mail is sent.

 

If you are spoolenable="yes", I'd set it to "no" and shove it to the mail server, instantly.

 

As far as Dave's suggestion of using a UUID as the filename is probably a pretty good one, as long as you're deleting the files, later.  This way, if the process somehow is being run simultaneously the files won't be overwritten by each other.

 

V/r,

 

^ _ ^

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 12, 2020 Apr 12, 2020

Copy link to clipboard

Copied

LATEST

Hi scottt3671444

Would it perhaps help if you used the principle of separation of concerns? You could handle images and mail separately. Something like this:

 

<!--- 
Create Bar Code
--->
<cfset myImages=arrayNew(1)>
<CFLOOP from="1" to="3" index="i">	
	<cfset myImages[i]=ImageNew("",200,70,"grayscale","white")> 
	<cfset attr = StructNew()> 
	<cfset attr.font="Archon Code 39 Barcode"> 
	<cfset attr.size=50> 
	<cfsetimageSetDrawingColor(myImages[i],"black")> 
	<cfsetimageAddBorder(myImages[i],1,"black")> 
	<cfsetimageDrawText(myImages[i],"*Index #i# *",15,50,attr)>
	<cfsetimageWrite(myImages[i], "ram:///barcode#i#.jpg", 1, "true")>
</CFLOOP>


<!--- 
Send mail
--->
<CFLOOP from="1" to="3" index="m">
<cfmail from="myemail@domain.au" to="myemail@domain.au" subject="Index #m#" type="html">
This email should have a Barcode for index #m#<br>
<img src="cid:Barcode#m#" width="200" height="70" alt="#m# Barcode" />
<cfmailparam file="ram:///barcode#m#.jpg"
contentid="Barcode#m#"
disposition="inline" /> 
</cfmail>

</CFLOOP>
 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation