Fun with "the templateimage"

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Klaus
Posts: 14206
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Fun with "the templateimage"

Post by Klaus » Thu Oct 31, 2019 10:11 am

Hi all,

after the overwhelming response from the mailing list, I decided to share this snippet here, too!

We know that "the templatexxxxxx" is a very helpful thingie.
But I did not know that we can even EXPORT something from the templateimage until I tried this:

Code: Select all

on mouseUp
  set the filename of the templateimage to "/Users/klaus2/Desktop/a nice image.jpg"

  ## This was a know (to me) feature
  put the formattedwidth of the templateimage into tFW
  put the formattedheight of the templateimage into tFH
  ## Now you can apply some "rule of three" to scale the image while preserving its ratio
  ## I'll leave that up to you... :-)

  ## I cheated a bit:
  set the width of the templateimage to 181
  set the height of the templateimage to 252

  ## But this one really suprised me:
  export the templateimage to file (specialfolderpath("desktop") & "/eltesto.jpg") as JPEG
  reset the templateimage
end mouseUp
No image object involved, how cool is that?! :-)


Best & happy Halloween

Klaus

bogs
Posts: 5480
Joined: Sat Feb 25, 2017 10:45 pm

Re: Fun with "the templateimage"

Post by bogs » Thu Oct 31, 2019 10:53 am

That is pretty neat, whatever made you try it?
Image

Klaus
Posts: 14206
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Fun with "the templateimage"

Post by Klaus » Thu Oct 31, 2019 10:57 am

I knew we can get the dimensions of an image this way, so I thought,
damn, why not go a step further, and my MacMini did not explode
but surprised me nicely with the result. :-)

So it was pure curiousity, and luckily I am not a cat! 8)

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10055
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Fun with "the templateimage"

Post by FourthWorld » Thu Oct 31, 2019 5:14 pm

Template objects can be useful for all kinds of one-offs. Here's a simple example of using the templateField to strip HTML tags:

Code: Select all

function HtmlToText pHtml
   put the htmlText of the templateField into tSaveText
   set the htmlText of the templateField to pHtml
   put the text of the templateField into tText
   set the htmlText of the templateField to tSaveText
   return tText
end HtmlToText
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply