Fun with the templateimage

classic Classic list List threaded Threaded
14 messages Options
Reply | Threaded
Open this post in threaded view
|

Fun with the templateimage

Richard Gaskin via use-livecode
Hi all,

we know that "the templatexxxxxx" is a very helpful thingie.

But I was really surprised that we can even EXPORT something
from the templateimage until I tried this:
-------------------------------------------------
on mouseUp

  ## My good ol' banana, older users of MC might remember that one :-D
  set the filename of the templateimage to "/Users/klaus2/Desktop/BANANA.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

Klaus

--
Klaus Major
https://www.major-k.de
[hidden email]


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Fun with the templateimage

Richard Gaskin via use-livecode
Or better yet: -- No error checking, assumes parameters are correct. Also not tested. :-)

on exportScaledImage pSourceFile, pDestFile, pScaleFactor, pFormat
   ## My good ol' banana, older users of MC might remember that one :-D
   set the filename of the templateimage to pSourceFile
   
   ## 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 round(tFW * (pScaleFactor /100))
   set the height of the templateimage to round(tFH * (pScaleFactor /100))
   
   ## But this one really suprised me:
   switch pFormat
      case "JPEG"
         export the templateimage to file (pDestFile) as JPEG
         break
      case "BMP"
         export the templateimage to file (pDestFile) as BMP
         break
      case "PNG"
         export the templateimage to file (pDestFile) as PNG
         break
   end switch
   
   reset the templateimage
end exportScaledImage


> On Oct 30, 2019, at 13:13 , Klaus major-k via use-livecode <[hidden email]> wrote:
>
> Hi all,
>
> we know that "the templatexxxxxx" is a very helpful thingie.
>
> But I was really surprised that we can even EXPORT something
> from the templateimage until I tried this:
<snip>
_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Fun with the templateimage

Richard Gaskin via use-livecode
The "import snapshot" command had an "at size" option added several
versions ago to facilitate some scaling tasks:

    import snapshot from the selectedObject at size 100,100

But oddly, no such option has been added to the "export snapshot" command.

--
  Richard Gaskin
  Fourth World Systems


Bob Sneidar wrote:

> Or better yet: -- No error checking, assumes parameters are correct. Also not tested. :-)
>
> on exportScaledImage pSourceFile, pDestFile, pScaleFactor, pFormat
>    ## My good ol' banana, older users of MC might remember that one :-D
>    set the filename of the templateimage to pSourceFile
>    
>    ## 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 round(tFW * (pScaleFactor /100))
>    set the height of the templateimage to round(tFH * (pScaleFactor /100))
>    
>    ## But this one really suprised me:
>    switch pFormat
>       case "JPEG"
>          export the templateimage to file (pDestFile) as JPEG
>          break
>       case "BMP"
>          export the templateimage to file (pDestFile) as BMP
>          break
>       case "PNG"
>          export the templateimage to file (pDestFile) as PNG
>          break
>    end switch
>    
>    reset the templateimage
> end exportScaledImage


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Fun with the templateimage

Richard Gaskin via use-livecode
In reply to this post by Richard Gaskin via use-livecode
Hi Bob,

> Am 31.10.2019 um 16:00 schrieb Bob Sneidar via use-livecode <[hidden email]>:
>
> Or better yet: -- No error checking, assumes parameters are correct. Also not tested. :-)
>
> on exportScaledImage pSourceFile, pDestFile, pScaleFactor, pFormat
>  ...
>   switch pFormat
>      case "JPEG"
>         export the templateimage to file (pDestFile) as JPEG
>         break
>      case "BMP"
>         export the templateimage to file (pDestFile) as BMP
>         break
>      case "PNG"
>         export the templateimage to file (pDestFile) as PNG
>         break
>   end switch
> ...

too bad LC does not like a variable for the target format:
...
export the templateimage to file pDestFile as pFormat
...
-> Compile error


Best

Klaus

--
Klaus Major
https://www.major-k.de
[hidden email]


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Fun with the templateimage

Richard Gaskin via use-livecode
When you call the command or when you save the script? Mine compiled. In any case I'll update it to use DO.

Bob S


> On Oct 31, 2019, at 10:01 , Klaus major-k via use-livecode <[hidden email]> wrote:
>
> Hi Bob,
>
>> Am 31.10.2019 um 16:00 schrieb Bob Sneidar via use-livecode <[hidden email]>:
>>
>> Or better yet: -- No error checking, assumes parameters are correct. Also not tested. :-)
>>
>> on exportScaledImage pSourceFile, pDestFile, pScaleFactor, pFormat
>> ...
>>  switch pFormat
>>     case "JPEG"
>>        export the templateimage to file (pDestFile) as JPEG
>>        break
>>     case "BMP"
>>        export the templateimage to file (pDestFile) as BMP
>>        break
>>     case "PNG"
>>        export the templateimage to file (pDestFile) as PNG
>>        break
>>  end switch
>> ...
>
> too bad LC does not like a variable for the target format:
> ...
> export the templateimage to file pDestFile as pFormat
> ...
> -> Compile error
>
>
> Best
>
> Klaus
>
> --
> Klaus Major
> https://www.major-k.de
> [hidden email]


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Fun with the templateimage

Richard Gaskin via use-livecode


> Am 31.10.2019 um 18:04 schrieb Bob Sneidar via use-livecode <[hidden email]>:
>
> When you call the command or when you save the script?

when hitting ENTER in the script editor = compiling

> Mine compiled.

???
I use LC 9.5 on macOS 10.14.6

> In any case I'll update it to use DO.
>
> Bob S
> ...
>>
>>> on exportScaledImage pSourceFile, pDestFile, pScaleFactor, pFormat
>>> ...
>>> switch pFormat
>>>    case "JPEG"
>>>       export the templateimage to file (pDestFile) as JPEG
>>>       break
>>>    case "BMP"
>>>       export the templateimage to file (pDestFile) as BMP
>>>       break
>>>    case "PNG"
>>>       export the templateimage to file (pDestFile) as PNG
>>>       break
>>> end switch
>>> ...
>> too bad LC does not like a variable for the target format:
>> ...
>> export the templateimage to file pDestFile as pFormat
>> ...
>> -> Compile error

Best

Klaus

--
Klaus Major
https://www.major-k.de
[hidden email]


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Fun with the templateimage

Richard Gaskin via use-livecode
Me too. I just tested it and got a 50% scaled image as a JPEG file. Let me try sending it to you again private email.

Bob S


> On Oct 31, 2019, at 10:07 , Klaus major-k via use-livecode <[hidden email]> wrote:
>
>
>
>> Am 31.10.2019 um 18:04 schrieb Bob Sneidar via use-livecode <[hidden email]>:
>>
>> When you call the command or when you save the script?
>
> when hitting ENTER in the script editor = compiling
>
>> Mine compiled.
>
> ???
> I use LC 9.5 on macOS 10.14.6
>
>> In any case I'll update it to use DO.
>>
>> Bob S
>> ...
>>>
>>>> on exportScaledImage pSourceFile, pDestFile, pScaleFactor, pFormat
>>>> ...
>>>> switch pFormat
>>>>   case "JPEG"
>>>>      export the templateimage to file (pDestFile) as JPEG
>>>>      break
>>>>   case "BMP"
>>>>      export the templateimage to file (pDestFile) as BMP
>>>>      break
>>>>   case "PNG"
>>>>      export the templateimage to file (pDestFile) as PNG
>>>>      break
>>>> end switch
>>>> ...
>>> too bad LC does not like a variable for the target format:
>>> ...
>>> export the templateimage to file pDestFile as pFormat
>>> ...
>>> -> Compile error
>
> Best
>
> Klaus
>
> --
> Klaus Major
> https://www.major-k.de
> [hidden email]
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Fun with the templateimage

Richard Gaskin via use-livecode
BTW do you use strict variables?

Bob S


> On Oct 31, 2019, at 10:20 , Bob Sneidar via use-livecode <[hidden email]> wrote:
>
> Me too. I just tested it and got a 50% scaled image as a JPEG file. Let me try sending it to you again private email.
>
> Bob S


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Fun with the templateimage

Richard Gaskin via use-livecode


> Am 31.10.2019 um 18:22 schrieb Bob Sneidar via use-livecode <[hidden email]>:
>
> BTW do you use strict variables?

NEVER! :-)

> Bob S
>
>> On Oct 31, 2019, at 10:20 , Bob Sneidar via use-livecode <[hidden email]> wrote:
>>
>> Me too. I just tested it and got a 50% scaled image as a JPEG file. Let me try sending it to you again private email.
>>
>> Bob S
--
Klaus Major
https://www.major-k.de
[hidden email]


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Fun with the templateimage

Richard Gaskin via use-livecode
In reply to this post by Richard Gaskin via use-livecode
Hi all,

> On Oct 31, 2019, at 10:01 , Klaus major-k via use-livecode <[hidden email]> wrote:
>>
>> Hi Bob,
>>
>>> Am 31.10.2019 um 16:00 schrieb Bob Sneidar via use-livecode <[hidden email]>:
>>>
>>> Or better yet: -- No error checking, assumes parameters are correct. Also not tested. :-)
>>>
>>> on exportScaledImage pSourceFile, pDestFile, pScaleFactor, pFormat
>>> ...
>>> switch pFormat
>>>    case "JPEG"
>>>       export the templateimage to file (pDestFile) as JPEG
>>>       break
>>>    case "BMP"
>>>       export the templateimage to file (pDestFile) as BMP
>>>       break
>>>    case "PNG"
>>>       export the templateimage to file (pDestFile) as PNG
>>>       break
>>> end switch
>>> ...
>>
>> too bad LC does not like a variable for the target format:
>> ...
>> export the templateimage to file pDestFile as pFormat
>> ...
>> -> Compile error

i filed an enhancement request:
<https://quality.livecode.com/show_bug.cgi?id=22437>


Best

Klaus
--
Klaus Major
https://www.major-k.de
[hidden email]


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Fun with the templateimage

Richard Gaskin via use-livecode
You removed the parenthesis. PUT 'EM BACK!  LOL!

Bob S


> On Oct 31, 2019, at 10:34 , Klaus major-k via use-livecode <[hidden email]> wrote:
>
> Hi all,
>
>> On Oct 31, 2019, at 10:01 , Klaus major-k via use-livecode <[hidden email]> wrote:
>>>
>>> Hi Bob,
>>>
>>>> Am 31.10.2019 um 16:00 schrieb Bob Sneidar via use-livecode <[hidden email]>:
>>>>
>>>> Or better yet: -- No error checking, assumes parameters are correct. Also not tested. :-)
>>>>
>>>> on exportScaledImage pSourceFile, pDestFile, pScaleFactor, pFormat
>>>> ...
>>>> switch pFormat
>>>>   case "JPEG"
>>>>      export the templateimage to file (pDestFile) as JPEG
>>>>      break
>>>>   case "BMP"
>>>>      export the templateimage to file (pDestFile) as BMP
>>>>      break
>>>>   case "PNG"
>>>>      export the templateimage to file (pDestFile) as PNG
>>>>      break
>>>> end switch
>>>> ...
>>>
>>> too bad LC does not like a variable for the target format:
>>> ...
>>> export the templateimage to file pDestFile as pFormat
>>> ...
>>> -> Compile error
>
> i filed an enhancement request:
> <https://quality.livecode.com/show_bug.cgi?id=22437>
>
>
> Best
>
> Klaus
> --
> Klaus Major
> https://www.major-k.de
> [hidden email]
>
>
> _______________________________________________
> use-livecode mailing list
> [hidden email]
> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Fun with the templateimage

Richard Gaskin via use-livecode
I should put a disclaimer in the comments of any code I write:

Note: The Author is not responsible for the loss of functionality or any consequences derived from to the alteration of any segment of this code.

:-)
Bob S


> On Oct 31, 2019, at 10:37 , Bob Sneidar <[hidden email]> wrote:
>
> You removed the parenthesis. PUT 'EM BACK!  LOL!
>
> Bob S
>
>
>> On Oct 31, 2019, at 10:34 , Klaus major-k via use-livecode <[hidden email]> wrote:
>>
>> Hi all,
>>
>>> On Oct 31, 2019, at 10:01 , Klaus major-k via use-livecode <[hidden email]> wrote:
>>>>
>>>> Hi Bob,
>>>>
>>>>> Am 31.10.2019 um 16:00 schrieb Bob Sneidar via use-livecode <[hidden email]>:
>>>>>
>>>>> Or better yet: -- No error checking, assumes parameters are correct. Also not tested. :-)
>>>>>
>>>>> on exportScaledImage pSourceFile, pDestFile, pScaleFactor, pFormat
>>>>> ...
>>>>> switch pFormat
>>>>>  case "JPEG"
>>>>>     export the templateimage to file (pDestFile) as JPEG
>>>>>     break
>>>>>  case "BMP"
>>>>>     export the templateimage to file (pDestFile) as BMP
>>>>>     break
>>>>>  case "PNG"
>>>>>     export the templateimage to file (pDestFile) as PNG
>>>>>     break
>>>>> end switch
>>>>> ...
>>>>
>>>> too bad LC does not like a variable for the target format:
>>>> ...
>>>> export the templateimage to file pDestFile as pFormat
>>>> ...
>>>> -> Compile error
>>
>> i filed an enhancement request:
>> <https://quality.livecode.com/show_bug.cgi?id=22437>
>>
>>
>> Best
>>
>> Klaus
>> --
>> Klaus Major
>> https://www.major-k.de
>> [hidden email]
>>
>>
>> _______________________________________________
>> use-livecode mailing list
>> [hidden email]
>> Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
>> http://lists.runrev.com/mailman/listinfo/use-livecode
>


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Fun with the templateimage

Richard Gaskin via use-livecode
In reply to this post by Richard Gaskin via use-livecode
OK New version with error checking, and also addresses the issue where Klaus could not compile:

on exportScaledImage pSourceFile, pDestFile, pScaleFactor, pFormat
   -- Validate parameters
   -- pSourceFile
   if not there is a file pSourceFile then \
         answer error "Source file does not exist!" as sheet ; exit exportScaledImage
   set the itemDelimiter to "/"
   
   -- pDestFile
   if not there is a folder (item 1 to -2 of pDestFile) then \
         answer error "Destination folder does not exist!" as sheet ; exit exportScaledImage
   
   -- pScaleFactor
   if not (pScaleFactor is a number) or not(pScaleFactor <1) then \
         answer error "Scale factor must be a percentage > 0!" as sheet ; exit exportScaledImage
   
   -- pFormat
   if not (pFormat is among the items of "JPEG/BMP/PNG") then \
         answer error "Valid formats are: JPEG, BMP or PNG." as sheet ; exit exportScaledImage
   
   -- set the source file as the template image and get dimensions
   set the filename of the templateimage to pSourceFile
   put the formattedwidth of the templateimage into tFW
   put the formattedheight of the templateimage into tFH
   
   -- scale the image to a round value
   set the width of the templateimage to round(tFW * (pScaleFactor /100))
   set the height of the templateimage to round(tFH * (pScaleFactor /100))
   
   -- convert file
   switch pFormat
      case "JPEG"
         put "export the templateimage to file " & quote & pDestFile & quote & " as JPEG" into tCommand
         break
      case "BMP"
         put "export the templateimage to file " & quote & pDestFile & quote & " as BMP" into tCommand
         break
      case "PNG"
         export the templateimage to file (pDestFile) as PNG
         put "export the templateimage to file " & quote & pDestFile & quote & " as PNG" into tCommand
         break
   end switch
   
   do tCommand
   
   -- reset
   reset the templateimage
end exportScaledImage

> On Oct 31, 2019, at 08:00 , Bob Sneidar <[hidden email]> wrote:
>
> Or better yet: -- No error checking, assumes parameters are correct. Also not tested. :-)
>
> on exportScaledImage pSourceFile, pDestFile, pScaleFactor, pFormat
>   ## My good ol' banana, older users of MC might remember that one :-D
>   set the filename of the templateimage to pSourceFile
>
>   ## 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 round(tFW * (pScaleFactor /100))
>   set the height of the templateimage to round(tFH * (pScaleFactor /100))
>
>   ## But this one really suprised me:
>   switch pFormat
>      case "JPEG"
>         export the templateimage to file (pDestFile) as JPEG
>         break
>      case "BMP"
>         export the templateimage to file (pDestFile) as BMP
>         break
>      case "PNG"
>         export the templateimage to file (pDestFile) as PNG
>         break
>   end switch
>
>   reset the templateimage
> end exportScaledImage
>
>
>> On Oct 30, 2019, at 13:13 , Klaus major-k via use-livecode <[hidden email]> wrote:
>>
>> Hi all,
>>
>> we know that "the templatexxxxxx" is a very helpful thingie.
>>
>> But I was really surprised that we can even EXPORT something
>> from the templateimage until I tried this:
> <snip>


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode
Reply | Threaded
Open this post in threaded view
|

Re: Fun with the templateimage

Richard Gaskin via use-livecode
Hi Bob,

> Am 31.10.2019 um 20:03 schrieb Bob Sneidar via use-livecode <[hidden email]>:
>
> OK New version with error checking, and also addresses the issue where Klaus could not compile:
>
> on exportScaledImage pSourceFile, pDestFile, pScaleFactor, pFormat
>   -- Validate parameters
>   -- pSourceFile
>   if not there is a file pSourceFile then \
>         answer error "Source file does not exist!" as sheet ; exit exportScaledImage
>   set the itemDelimiter to "/"
>
>   -- pDestFile
>   if not there is a folder (item 1 to -2 of pDestFile) then \
>         answer error "Destination folder does not exist!" as sheet ; exit exportScaledImage
>
>   -- pScaleFactor
>   if not (pScaleFactor is a number) or not(pScaleFactor <1) then \
>         answer error "Scale factor must be a percentage > 0!" as sheet ; exit exportScaledImage
>
>   -- pFormat
>   if not (pFormat is among the items of "JPEG/BMP/PNG") then \
>         answer error "Valid formats are: JPEG, BMP or PNG." as sheet ; exit exportScaledImage
>
>   -- set the source file as the template image and get dimensions
>   set the filename of the templateimage to pSourceFile
>   put the formattedwidth of the templateimage into tFW
>   put the formattedheight of the templateimage into tFH
>
>   -- scale the image to a round value
>   set the width of the templateimage to round(tFW * (pScaleFactor /100))
>   set the height of the templateimage to round(tFH * (pScaleFactor /100))

## Just tested with DO, this does work WITHOUT switch 8-)
put "export the templateimage to file " & quote & pDestFile & quote & " as" && pFormat into tCommand

>   do tCommand
>   -- reset
>   reset the templateimage
> end exportScaledImage

Best

Klaus

--
Klaus Major
https://www.major-k.de
[hidden email]


_______________________________________________
use-livecode mailing list
[hidden email]
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode