REVO2700 Image Drag and drop 2 Q&/* Image Drag and Drop Stack By Eric Chatonet 2/20/05 http://www.sosmartsoftware.com/ */ on preOpenStack if the short name of me <> the short name of this stack then exit preOpenStack set the style of this stack to "modeless" set the loc of this stack to the screenLoc end preOpenStack C X +#005 How to drag and drop and store images U Lucida Grande U Lucida Grande W Lucida Grande U Lucida Grande cREVGeneral debugObjects breakpoints breakpointstates breakpointconditions stackfileversion 2.7 P ]on dragEnter if "image" is in the target then set the acceptDrop to true -- then dragdrop message will be sent to any image end dragEnter ------------------------------- on dragDrop -- send to an image when the user drags and drop a file onto it local tFilePath ----- -- is the dragged and dropped file a valid image file? put the dragData into tFilePath switch GetExtension(tFilePath) -- see this function that returns the file extension extracted from the file path below case "error: could not find extension" -- may happen with MacOS switch the platform case "MacOS" -- the file has no extension: we try to get its file type (MacOS only) if FileInfo(tFilePath,"type") is not among the items of "JPEG,GIFf,PNGf,PICT,BMP " then AnswerErr tFilePath -- see this function below else ImportImage tFilePath,the hilitedButton of grp "Method" -- -- the hilitedButton of grp "Method" specifies here the method: see ImportImage handler below break ----- default AnswerErr tFilePath -- end switch break ----- case "JPG" case "png" case "gif" case "bmp" -- main image types supported for display into Revolution images -- more types can be used with players ImportImage tFilePath,the hilitedButton of grp "Method" -- break ----- default AnswerErr tFilePath -- end switch end dragDrop --------------------------------- on ImportImage pFilePath,pMethod constant kMaxDim = 200 -- max width or max height of any imported image in pixels (value for our demo) local tCurImg,tWidth,tHeight,tRect,tImageData,tImageFolder,tNewFilePath,tOriginalSize,tTempFilePath,tNewSize ----- set the cursor to watch put the long ID of the target into tCurImg -- always better to work with a complete reference ----- -- initialization: lock screen set the text of tCurImg to empty set the height of tCurImg to kMaxDim set the width of tCurImg to kMaxDim ----- set the filename of tCurImg to pFilePath ----- -- sets the right dimensions, proportions and the loc of the image put the formattedWidth of tCurImg into tWidth put the formattedHeight of tCurImg into tHeight if tWidth > tHeight then set the height of tCurImg to round(tHeight * (kMaxDim/tWidth)) else set the width of tCurImg to round(tWidth * (kMaxDim/tHeight)) set the loc of tCurImg to the loc of the owner of tCurImg -- centers image into its own group unlock screen -- in fact, these first lines are method 1 ----- switch pMethod case 1 -- links to the original file -- the job is already done! -- following code is for demo purpose only: put FileInfo(pFilePath,"size") into tOriginalSize -- answer info "
Method 1
" & cr & "" & cr & "Image is only linked to the original file:" & cr \ & "
The size of the stack does not change.
" & cr & "File size:" && tOriginalSize &"
" as sheet break ----- case 2 -- stores optimized image into current stack -- method 2 adds the following procedure to method 1: set the JPEGQuality to the thumbpos of scrollbar "CompBar" -- jpeg quality (between 1 and 100 : 50/60 is a good average) put GlobalObjRect(the rect of tCurImg) into tRect -- see this function below ----- export snapshot from rect tRect to tImageData as JPEG -- exports the image data to a variable set the text of tCurImg to tImageData -- sets image data ----- -- following code is for demo purpose only: put FileInfo(pFilePath,"size") into tOriginalSize -- put the defaultFolder & slash & "tempFile" into tTempFilePath put tImageData into url("binfile:" & tTempFilePath) put FileInfo(tTempFilePath,"size") into tNewSize -- delete file tTempFilePath answer info "Method 2
" & cr & "" & cr & "Image is stored into the stack.
" & cr \ & "Original image:" && tOriginalSize & ".
" & cr & "Optimized stored image:" && tNewSize & ".
" as sheet break ----- case 3 -- links to an optimized file created on the fly -- method 3 adds the following procedure to method 1: set the JPEGQuality to the thumbpos of scrollbar "CompBar" -- jpeg quality between 1 and 100 put GlobalObjRect(the rect of tCurImg) into tRect -- see this function below ----- creates an image folder if needed put the defaultFolder & slash & "Images Test" into tImageFolder if there is no folder tImageFolder then create folder tImageFolder set the itemDel to slash put tImageFolder & slash & StripExtension(last item of pFilePath) & ".jpg" into tNewFilePath ----- export snapshot from rect tRect to url("binfile:" & tNewFilePath) as JPEG -- exports the image data to a file set the filename of tCurImg to tNewFilePath -- links the image to the new file ----- -- following code is for demo purpose only: put FileInfo(pFilePath,"size") into tOriginalSize -- put FileInfo(tNewFilePath,"size") into tNewSize -- answer info "Method 3
" & cr & "" & cr & "Image is linked to" && tNewFilePath & ".
" & cr \ & "Original image:" && tOriginalSize & ".
" & cr & "Optimized exported image:" && tNewSize & ".
" as sheet end switch ----- end ImportImage ####################################### -- complementary handlers and functions ####################################### on AnswerErr pFilePath answer error pFilePath && "does not appear to be a valid image." with "Sorry" exit to top end AnswerErr --------------------------------- function GlobalObjRect pRect -- this function converts a local rect to a global rect and returns the result return item 1 of pRect + the left of this stack,item 2 of pRect + the top of this stack,item 3 of pRect + the left of this stack,item 4 of pRect + the top of this stack end GlobalObjRect --------------------------------- function GetExtension pFilePath -- this function returns the extension of a file (its path is passed as a parameter) local tFileName ----- set the itemDel to slash put item -1 of pFilePath into tFileName if "." is not in tFileName then return "error: could not find extension" repeat with i = the number of chars of tFileName down to 1 if char i of tFileName = "." then exit repeat end repeat return char (i+1) to (the number of chars of tFileName) of tFileName end GetExtension --------------------------------- function StripExtension pFileName -- this function returns the filename without any extension if "." is not in pFileName then return pFileName repeat with i = the number of chars of pFileName down to 1 if char i of pFileName = "." then exit repeat end repeat return char 1 to (i-1) of pFileName end StripExtension ############################################ -- code below is used for demo purposes only ############################################ function FileInfo pFilePath,pInfo -- this function returns any file size, file creation date, file modification date, file creator or file type whose path is passed as a parameter -- according to a complete file path and the value of pInfo parameter local tDefaultFolder,tFiles,tFilter,tSize,tDate ----- put the defaultFolder into tDefaultFolder set the itemDel to slash set the defaultFolder to item 1 to -2 of pFilePath put urldecode(the long files) into tFiles put last item of pFilePath & "*" into tFilter filter tFiles with tFilter set the defaultFolder to tDefaultFolder ----- set the itemDel to comma switch pInfo case "size" put item 2 of tFiles + item 3 of tFiles into tSize put tSize div 1024 into tSize if tSize > 1000 then set the numberFormat to "0.0" put tSize / 1024 && "Mb" into tSize else put tSize && "Kb" into tSize return tSize break case "creation" put item 4 of tFiles into tDate convert tDate from seconds to system date and system time return tDate break case "modification" put item 5 of tFiles into tDate convert tDate from seconds to system date and system time return tDate break case "type" return char -4 to -1 of tFiles break case "creator" return char -8 to -5 of tFiles end switch end FileInfo X cREVGeneral breakPoints scripteditorvscroll 714scripteditorselection 1688 _ ` d @ _ Tabs } oon menuPick pNewTab,pOldTab lock screen hide grp pOldTab show grp pNewTab unlock screen end menuPick h: Action Discussion cREVGeneral revUniqueID 1108897407452 ` Action i V . cREVGeneral revUniqueID 1108897664141 , Method ,i0 _on mouseUp set the enabled of grp "Compression" to the hilitedButton of me <> 1 end mouseUp ZC Method: cREVGeneral revUniqueID 1108891894167 $ Rad1 hd wZ Link to Original File cREVGeneral revUniqueID 1108891405342 &