KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Utility method to rotate a picture
PRODUCT: 4D | VERSION: 19 | PLATFORM: Mac
Published On: March 14, 2022

Below is a utility method to rotate a picture using the native OS X command “SIPS” (scriptable image processing system):

/*--------------------
Method: rotatePicture
Description: Rotates a picture 90, 180, or 270 degrees clockwise.
Parameters:
$1 (Pointer) - Pointer to the picture variable.
$2 (Longint) - Number of degrees (90, 180, or 270 only).
---------------------*/
C_POINTER($1; $picture_p)
C_LONGINT($2; $degrees_l)
C_TEXT($tempPath_t; $command_t)

If (Count parameters>=2) & (Is macOS) // Mac only
   $picture_p:=$1
   $degrees_l:=$2
  
   If ($degrees_l=90) | ($degrees_l=180) | ($degrees_l=270)
     $tempPath_t:=Get 4D folder(Active 4D Folder)+"temp.png"
     WRITE PICTURE FILE($tempPath_t; $picture_p->)
  
     $command_t:="sips -r "+String($degrees_l)+" \""+Convert path system to POSIX($tempPath_t)+"\""
     LAUNCH EXTERNAL PROCESS($command_t)
  
     READ PICTURE FILE($tempPath_t; $picture_p->)
     DELETE DOCUMENT($tempPath_t)
   Else
     ALERT("Number of degrees must be 90, 180, or 270.")
   End if
End if


For example, given a form with a button and picture object:



Object method for Rotate button:

rotatePicture(->pictureVariable; 90)

Result after clicking Rotate once:



NOTE: This utility method will only work on macOS.