Rotating an image
Frank Leahy
frank at backtalk.com
Sat Feb 7 03:42:22 EST 2004
Jim,
Here's my RotateImage function, hope it helps.
This assumes you've got an image on your card called "Current Image".
In my version of this function, I first scale the image down to a
thumbnail size so the user can see what image I'm working on, then I
call lock screen, then I do the rotation code here. After the rotation
is complete I create a new thumbnail of the rotated image and then call
unlock screen. This way the user only sees the two thumbnails, never
the intermediate larger images.
on RotateImage theFileName, direction
put "binfile:" & theFileName into urlCmd
put URL urlCmd into image "Current Image"
put the formattedHeight of image "Current Image" into fh
put the formattedWidth of image "Current Image" into fw
if direction = "left" then
rotate image "Current Image" by 90
else if direction = "right" then
rotate image "Current Image" by -90
end if
choose browse tool
put the rect of image "Current Image" into imageRect
set the itemDelimiter to ","
if fw > fh then
put fw - fh into delta
put delta div 2 into theLeftMargin
put delta - theleftMargin into theRightMargin
add theLeftMargin to item 1 of imageRect
subtract theRightMargin from item 3 of imageRect
else if fw < fh then
put fh - fw into delta
put delta div 2 into theTopMargin
put delta - theTopMargin into theBottomMargin
add theTopMargin to item 2 of imageRect
subtract theBottomMargin from item 4 of imageRect
end if
crop image "Current Image" to imageRect
-- Put whatever jpeg quality level you want here,
-- but it probably makes sense to use a qualityLevel of 100 for
rotation
put 100 into qualityLevel
set the jpegQuality to qualityLevel
set the paintCompression to "jpeg"
export image "Current Image" to URL ("binfile:" & theFileName) as JPEG
put the result into theResult -- you could check this if you wanted to
set the fileName of image "Current Image" to empty
end RotateImage
-- Frank Leahy
More information about the use-livecode
mailing list