How to add a “Resize Image” Procedure in Clarion 7

Yesterday I was adding "Internet Profile" functionality for Users. That is, a Description and Image can be entered in the back-end which will then show on the public website, under "Our Team".

Getting the image into my file structure (within the web folder) was no problems (have it in a number of places for all kinds of media), but Profile images have an important rule:

  • They must be small.

And then a second, more general, rule occurred to me.

  • Standardise ALL images uploaded into the system.

With these in mind I opened up my Data DLL app and got to work.

First things first. Two global templates have to be added before going any further.

1. The Clarion FreeImage template.


And 2. The Capesoft Draw global template.


As you can see, in the Options tab of the Draw global template dialogue, we’ve ticked the "Use DrawImage Functionality" checkbox. IMPORTANT!

Then we get onto creating the procedure.

I wanted to pass the Source and Destination paths (eg. c:\\images\\profile.png), and the Max Width and Height. That’s it.

Oh! And because it’s good practice in my books, I’ve got a return variable.


Then we open up the Window and add the Draw control (from the Control Templates pad).


And finally we come to the code. The rule is to make sure the code is called AFTER the Window is opened. I’ve made a routine and called it in the "After Window Opened" embed.

ResizeImage routinedataimage:Width longimage:Height longimage:BitDepth longimage:Type longcode!-! Init!—-if not Drawer4.useDrawImageDrawer4.InitDrawImage()endDrawer4.Blank(COLOR:White)Drawer4.diGetImageInfo(pSourcePath,image:Width,image:Height,image:BitDepth,image:Type)Drawer4.BestFit(image:Width,image:Height,Drawer4.width,Drawer4.height,image:Width,image:Height)Drawer4.Resize(image:Width,image:Height)Drawer4.diReadImage(pSourcePath, 1 + (Drawer4.width-image:Width)/2, 1 + (Drawer4.height-image:Height)/2, image:Width, image:Height)Drawer4.Display()Drawer4.WritePNG(pDestPath)post(EVENT:CloseWindow)

(Edit: Some changes made thanks to Sean (from Capesoft) in comment below. Thanks Sean!)

This code will take in your image, resize it to "best fit" within the Max Width and Height you passed, and save it to the Destination Path as a PNG image file.


Leave a Reply

Your email address will not be published. Required fields are marked *