Thanks Cannon.
Your code looked vaguely familiar to me. I had not thought to look and see if I
already had a method to rotate pictures. Sure enough I do. Looks very similar
to yours, even uses the same variable conventions. Perhaps you gave this to me
back in 2011?
In any event thanks. I am going to use your method as it is a bit more compact
than mine. Mine is a tad faster, however. I posted mine below for comparison.
John
——————————]
C_PICTURE($1;$MyPicture)
C_LONGINT($2;$rotation)
// ----------------------------------------------------
$error:=SVG_Set_error_handler ("SVG_error_mgmt")
$MyPicture:=$1
$rotation:=$2
$temporaryPictureFilePath:=Temporary folder+"tempPicture.jpg"
WRITE PICTURE FILE($temporaryPictureFilePath;$MyPicture) //write the
picture to file so we can get it with a URL
PICTURE PROPERTIES($MyPicture;$width;$height)
If ($width>=$height) //get the largest dimension of the picture
$svgAreaSize:=$width
Else
$svgAreaSize:=$height
End if
$SVGRef:=SVG_New ($svgAreaSize;$svgAreaSize) //make the new SVG area
big enough to hold the picture rotated
If ($width>=$height) //center the picture in the SVG area
$picRef:=SVG_New_image
($SVGRef;"file://"+$temporaryPictureFilePath;0;($width/2)-($height/2);$width;$height)
Else
$picRef:=SVG_New_image
($SVGRef;"file://"+$temporaryPictureFilePath;($height/2)-($width/2);0;$width;$height)
End if
SVG_SET_TRANSFORM_ROTATE
($picRef;$rotation;$svgAreaSize/2;$svgAreaSize/2) //rotate it
$MyPicture:=SVG_Export_to_picture ($SVGRef) //The image is correctly
rotated but is now in a square picture
Case of //crop the picture back down to the size of the image if the
image is not square
: ($width>$height)
TRANSFORM
PICTURE($MyPicture;Crop;($width/2)-($height/2);0;$height;$svgAreaSize)
: ($height>$width)
TRANSFORM
PICTURE($MyPicture;Crop;0;($height/2)-($width/2);$svgAreaSize;$width)
End case
$0:=$MyPicture
----------------------------
> On Jun 22, 2019, at 11:37 AM, Cannon Smith via 4D_Tech <[email protected]>
> wrote:
>
> Hi John,
>
> Here is the code from a method I use called Photo_Rotate:
>
> //This method rotates a picture. While it will rotate the picture to
> //any angle, this method is really expecting it to rotate 90˚, 180˚,
> //or 270˚.
>
> C_PICTURE($1;$gPicture)
> C_REAL($2;$rDegrees) //Expects 90, 180, or 270
> C_PICTURE($0)
>
> $gPicture:=$1
> $rDegrees:=$2
>
> C_LONGINT($lWidth;$lHeight)
> C_TEXT($svgRef;$imageRef)
>
> PICTURE PROPERTIES($gPicture;$lWidth;$lHeight)
> $svgRef:=SVG_New ($lWidth;$lHeight)
> $imageRef:=SVG_New_embedded_image ($svgRef;$gPicture;0;0;".jpeg")
>
> If (($rDegrees=90) | ($rDegrees=270))
> SVG_SET_TRANSFORM_ROTATE ($imageRef;$rDegrees;($lHeight/2);($lWidth/2))
> SVG_SET_TRANSFORM_TRANSLATE
> ($imageRef;(($lHeight-$lWidth)/2);(($lWidth-$lHeight)/2))
> DOM SET XML
> ATTRIBUTE($svgRef;"height";String($lWidth);"width";String($lHeight))
> Else //180
> SVG_SET_TRANSFORM_ROTATE ($imageRef;$rDegrees;($lWidth/2);($lHeight/2))
> End if
>
> $0:=SVG_Export_to_picture ($svgRef)
> SVG_CLEAR ($svgRef)
>
> HTH.
>
> --
> Cannon.Smith
> Synergy Farm Solutions Inc.
> Aetna, AB Canada
> <[email protected]>
> <www.synergyfarmsolutions.com>
>
>
>> On Jun 22, 2019, at 3:34 PM, JOHN BAUGHMAN via 4D_Tech
>> <[email protected]> wrote:
>>
>> If not 4D commands, what is the quickest and easiest way to rotate a picture
>> in a picture variable? Anyone got code they could share?
>
> **********************************************************************
> 4D Internet Users Group (4D iNUG)
> Archive: http://lists.4d.com/archives.html
> Options: https://lists.4d.com/mailman/options/4d_tech
> Unsub: mailto:[email protected]
> **********************************************************************
**********************************************************************
4D Internet Users Group (4D iNUG)
Archive: http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub: mailto:[email protected]
**********************************************************************