Tech Tip: Rotating Pictures in 4D
PRODUCT: 4D | VERSION: 12 | PLATFORM: Mac OS X
Published On: October 5, 2010
4D does not have a native command that will rotate an image. You can use the 4D command TRANSFORM PICTURE to translate and flip images but not to rotate them. However, if you are on a Mac you can do all kinds of image tricks beyond 4D's native capabilities.
The OS X UNIX command "SIPS" (scriptable image processing system) and the 4D command LAUNCH EXTERNAL PROCESS can be used to manipulate one image or a folder full of images. You can refer to this Apple Tech Note for more info on SIPS:
https://developer.apple.com/library/mac/#technotes/tn/tn2035.html
As an example, the method below will rotate an image in one degree increments, positive numbers clockwise, negative numbers counter-clockwise:
C_POINTER($Image_P;$1) C_TEXT($FileName_T;$2;$Script_T) C_LONGINT($Degrees_L;$3) $Image_P:=$1 $FileName_T:=$2 $Degrees_L:=$3 $FilePath_T:=Get 4D folder(Active 4D Folder)+$FileName_T WRITE PICTURE FILE($FilePath_T;$Image_P->) // v12 $scriptPath_T:=Convert path system to POSIX($FilePath_T) // v11 $POSIX_Path2_T:="/Volumes/"+Replace string($FilePath_T;":";"/") $Script_T:="sips -r "+String($Degrees_L)+" "+$scriptPath_T LAUNCH EXTERNAL PROCESS($Script_T) READ PICTURE FILE($FilePath_T;$Image_P->) DELETE DOCUMENT($FilePath_T) |
You can do the same with a batch of images by simply applying the rotation to all images contained in a folder. The command is the following:
sips -r 90 /Users/youraccount/Desktop/Folder/*.png |
SIPS can convert jpeg (Jfif & Xiff), TIFF, GIF, and PNG files according to the Apple technical note. By experience it can also handle other formats.
$POSIX_Path2_T:="\"/Volumes/"+Replace string($FilePath_T;":";"/")+"\""