Images in web views

I was wondering whether there exists a better way to display images in a web view. Currently I include the URL to the attachment in the IMG tag. However, since I do not have any control on the size of the attachments, it takes sometimes quite some time to load a view. Thanks for you comments.

John

Subject: RE: Images in web views

If the only copy of your image is the one in a file attachment, then the only way to display that image is to send the complete file to the browser.

If you want to display a thumbnail, you would have to store the thumbnail in the document (or in some document) so that you could use that image instead. Notes has no facility to let you create thumbnails automatically, but there’s software that will do that – you could call that software from a Notes agent to process recently created documents and generate the thumbnails.

If you just want to avoid displaying any picture above a certain size, you could use @AttachmentNames in conjunction with @AttachmentLengths to decide which images to display. E.g. to display only images < 10000 bytes, you could do something like:

_images :=

@If(@AttachmentNames != “”;

@Trim(@Right( @Text(@Sign(@AttachmentLengths-10000)) + “" + @AttachmentNames); "-1”));

“–none–”

);

@If(_images[1] = “”;

“image too large”;

_images[1] = “–none–”;

“no images”;

“<img src="/” + … + _images + “">”

)

Subject: RE: Images in web views

As Andre suggested, the best way is to create seperate thumbnail attachments.

Let’s say your view contains 30 images of 100Kb each. When you tags to resize the image, you are sending 3 Mb (not counting text) to the browser for your view. Usually a small thumbnail image is no larger than 2Kb, so when you use thumbnail images in your view, your view size would be reduced to 60Kb (again, not counting text), or as my calculator claims: an improvement of 5000% !! How about that for speeding up your views… It sure makes the extra 60Kb storage required well worth it.

Any easy way to create this extra thumbnail image, is to use a webquery save agent. I’ve attached some sample code to show you how this can be accomplished.

Note: This code uses a commercial lsx to create the thumbnails. You can find more info on the thumbnailer lsx here: http://www.peopleware.be/peopleware/public/tnreg.nsf

Option Public

Uselsx “Thumbnailer”

Use “ThumbnailUtils”

Sub Initialize

On Error Goto errorhandler

Dim s As notessession

Dim tn As thumbnailer

Dim doc As notesdocument

Dim embeddedobj As notesembeddedobject

Dim attnames As Variant

Dim tmpdir As String

Dim tmpfilename As String

Dim rt As notesrichtextitem

Set s = New notessession

Set tn = New thumbnailer

Set doc = s.documentcontext

'process document only once

If doc.thumbnailcreated(0) <> “” Then Exit Sub

If Not doc.hasembedded Then Exit Sub

'get attachmentname

attnames = Evaluate(|@attachmentnames|, doc)

tmpdir = BuildTempDir()

tmpfilename = tmpdir + attnames(0)

'extract file

Set embeddedobj = doc.GetAttachment(attnames(0))

Call embeddedobj.ExtractFile(tmpfilename)

'create custom thumbnail

tn.quality = 90 'compress image to 90% of it’s quality

tn.width = 70 'image should be maximum 70 pixels wide

tn.height = 70 'image should be maximum 70 pixels high

tn.includefilename = False 'don’t annotate filename on image

Call tn.createthumbnailimage(tmpfilename, tmpdir + “\thumbnail.jpg”)

'attach thumbnail

Set rt = doc.getfirstitem(“Body”)

Call rt.embedobject(EMBED_ATTACHMENT, “”, tmpdir + “\thumbnail.jpg”)

'don’t process document again

doc.thumbnailcreated = “1”

'clean up

Killdir(tmpdir)

Exit Sub

errorhandler:

doc.error = "Line " + Cstr(Erl) + ": " + Error

Exit Sub

End Sub

Subject: RE: Images in web views

I use this type of thing to control the image size - it loads very quickly. If you set WIDTH=100 all will resize keeping the aspect ratio intact eg if image is 200 * 150 it will appear as 100 * 75 if 200 200 then 100100. This keeps the view neat if there are different size images.

dbname := @ReplaceSubstring(@ReplaceSubstring(@Subset(@DbName; -1);" “;”+“);”\“;”/");

Subject: RE: Images in web views

Trouble is John was complaining about the image download time – not the size on screen. The height and width settings don’t affect download time.