clarion 7

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

by Stu Andrews on April 26, 2010

in Blog

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.

23-04-2010-1-36-16-PM

And 2. The Capesoft Draw global template.

23-04-2010-1-37-32-PM

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.

23-04-2010-1-37-57-PM

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

23-04-2010-1-42-40-PM

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.

Fantastic!

Popularity: 4%

{ 0 comments }

Late To The Party

November 29, 2007

I know, I’ve come very late to the party. Back in May, Bob Foreman posted http://www.softvelocity.net/community/blogs/clarion_news/archive/2007/05/03/1635.aspx this little wonder on Vista and Clarion 6. Both things I had never bothered to try and fix, because I figured Vista was magical and I’d heard these things were just the way it was. I’m very inquisitive .. [...]

Read it →

The TooMany Bobs Productions

September 20, 2007

There has been quite a bit of activity on the Soft Velocity blog of late. And it’s highlighted with a number of videos. These are showing particular aspects of Clarion 7. Taking the time, I found, to watch them with Clarion 7 open so you can go and see exactly what is being talked about, [...]

Read it →

A Picturesque View

September 12, 2007

This may be a boring post for some.   A Long, Boring, Picturesque Drive Through A Lot Of Screens   Read On .. I’m going to walk through a bunch of screenies, maybe commenting a little as we go along. Kind of like a Saturday Night Family Slideshow with friends, where the Dad thinks it’s [...]

Read it →

The Good-Looking Cousin Has Arrived

September 7, 2007

The more I think about it, the more Clarion .NET excites me. But for the moment, I am content to gaze upon the wonderful glory of a new IDE .. Clarion 7 (Beta) has made it to my doorstep. It was a strange surreal moment. This was no doubt due to my being up at [...]

Read it →

Action Station!

August 9, 2007

There’s movement at the Clarion Station! First. This is good for the community. Second. I’m talking about the news as per a few hours ago. Bob Z has blogged that Clarion 7 will be released (in it’s current, I think, form) to the CSP (Core Subscription) peeps. This is action. Movement. Even if SV has [...]

Read it →

Aussie DevCon 2007 .. Part 3 (Saturday Content)

June 1, 2007

This is definitely spanning more posts than I figured. But then, I wrote more notes than last year. A lot more. Anyway, we are looking at the Saturday content today, which was the most diverse of the days in terms of speakers and .. content. Ha. Bob, Bruce, Geoff, Russ .. and myself. Actually, looking [...]

Read it →