简体   繁体   中英

Need Coldfusion strategy for watermarking 11 GB of jpegs

I have a client who wants to watermark their images on a IIS server running ColdFusion 10. I'm looking for any way to avoid mutilating all images with a batch update and having to manage both a version watermarked and one for the original.

Can watermarking be done on the fly for high-rez images with ColdFusion and not overload the server? I'm thinking if I exclude the folder from search engine traffic with robots.txt then it would not be more than the visitors' traffic and this could be possible. A flexible solution like this would be ideal, allowing the client to update the look of the watermark without re-batching.

How would you handle it?

This is actually covered in the Adobe ColdFusion documentation.

First there is Manipulating ColdFusion images - near the bottom of the page is a section on Creating watermarks (Each of the bullets is discussed in further detail on that page)

A watermark is a semitransparent image that is superimposed on another image. One use for a watermark is for protecting copyrighted images. To create a watermark in ColdFusion, you use the ImageSetDrawingTransparency function with the ImagePaste function. You can create a watermark image in one of three ways:

  • Create a watermark from an existing image file. For example, you can use a company logo as a watermark.
  • Create a text image in ColdFusion and apply the image as a watermark. For example, you can create a text string, such as Copyright or PROOF and apply it to all the images in a photo gallery.
  • Create a drawing image in ColdFusion and use it as a watermark. For example, you can use the drawing functions to create a green check mark and apply it to images that have been approved.

Then there is Writing images to the browser - that discusses how to write images directly to the browser without writing them to disk.

Use the writeToBrowser action of the cfimage tag to display images directly in the browser without writing them to files. This technique is useful for testing the appearance of a ColdFusion image.

And they even have Generating a gallery of watermarked images under Application examples that use ColdFusion images - about half-way down that page.

These examples should get you going.

Ben Nadel's blog series covers this well: http://www.bennadel.com/blog/775-Learning-ColdFusion-8-CFImage-Part-III-Watermarks-And-Transparency.htm

It depends how large the images are really as to server load, and how meaty your server is.

What I do is render the image via ajax call (ie put a spinner in place till it's loaded, then swop out the HTML with the rendered/watermarked image).

You could also easily have a cache folder of already watermarked images, and then the script does fileExists() on the cache folder, and serves that if it already exists.

A good solution would be to create a new folder for the images that have been watermarked (eg /images/watermarked/) and then add a web server rewrite rule that checks to see if the file exists in the folder, if it doesn't exist in the folder then the redirect rule runs the request through CF and allows you to generate the watermarked image and store it in the folder for future use.

You can use the IIS rewrite module to do this, look at this link for a similar solution: If File exists, return file, If File does not exit, Rewrite

That solution has the benefit of serving the images through the web server and avoiding involving CF in most cases. Then if you have a new watermark you just empty out the /images/watermarked/ folder and it will start generating new ones as requests come in.

If you have more complicated needs then you might want to check out mod_xsendfile (Apache module or IIS module from Helicon).

This answer ( How to add watermarks to images via command line - Hopefully using Irfanview ) looks like the business, just serving a temporary file, generated on the fly with that method. (It doesn't use IrfanView). I'm unfamiliar with ColdFusion, so that's up to you.

Not directly related to your question, but if your client doesn't want the non-watermarked images to be directly accesible via web, I think that just excluding the folder from search engines with robots.txt would be insufficient, as you are effectively pointing anyone who takes a look at robots.txt to that folder. You should put your original images on a not web-accesible directory.

This is a simple logic I used for processing images residing in an IIS server that was mounted onto my linux server drive. From latter I watermark each images and segregate them to groups each group represented by a folder. I process around 800-1000 images per day of really high quality (min zize of file 10MB). However I downsize the quality using the quality parameter if ImgaWrite function in CF10.

<cfloop array="myArrayofStructs" index="carr">
<cfif len(carr.tempPath) GT 0>              
 <cfif !directoryexists(Dirdestn&carr.tempPath&"/")>
    <cfset DirectoryCreate(Dirdestn&carr.tempPath&"/")>
 <cfelse>
    <!---Do Nothing--->
 </cfif>

<cfset destn=Dirdestn&carr.tempPath&"/"&carr.photoid&".jpg">

<cfset source=Expandpath("/imagebank/"&carr.filename)>
<cfif fileexists(Expandpath("/imagebank/"&carr.filename)) AND IsImageFile(Expandpath("/imagebank/"&carr.filename))>
    <cfif !fileexists(destn)>
     <cfimage source="#source#" name="image_1">
     <cfset imagepaste(image_1, watermark, 500, 0)>                                     <cfset imageWrite(image_1, destn,0)>
    </cfif>
</cfif>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM