Fun with the templateimage

Klaus major-k klaus at major-k.de
Thu Oct 31 15:13:15 EDT 2019


Hi Bob,

> Am 31.10.2019 um 20:03 schrieb Bob Sneidar via use-livecode <use-livecode at lists.runrev.com>:
> 
> 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
klaus at major-k.de





More information about the use-livecode mailing list