Rotate Picture

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

Rotate Picture

4D Tech mailing list
Is it possible to rotate a picture using native 4D commands? Google search finds references to Miyako’s rotate picture component, SVG, GitHub, etc.

I do not see any way to do it with Transform Picture.

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?

Thanks,

John


John Baughman
Kailua, Hawaii
(808) 262-0328
[hidden email]

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Rotate Picture

4D Tech mailing list
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
<[hidden email]>
<www.synergyfarmsolutions.com>


> On Jun 22, 2019, at 3:34 PM, JOHN BAUGHMAN via 4D_Tech <[hidden email]> 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:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Rotate Picture

4D Tech mailing list
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 <[hidden email]> 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
> <[hidden email]>
> <www.synergyfarmsolutions.com>
>
>
>> On Jun 22, 2019, at 3:34 PM, JOHN BAUGHMAN via 4D_Tech <[hidden email]> 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:[hidden email]
> **********************************************************************

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Rotate Picture

4D Tech mailing list
For all I remember you gave it to me! :-)

Glad it works.

--
Cannon.Smith
Synergy Farm Solutions Inc.
Aetna, AB Canada
<[hidden email]>
<www.synergyfarmsolutions.com>


> On Jun 22, 2019, at 6:28 PM, JOHN BAUGHMAN via 4D_Tech <[hidden email]> wrote:
>
> 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.

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Rotate Picture

4D Tech mailing list
In reply to this post by 4D Tech mailing list
I think the default export option is "copy"

if you don't SVG_CLEAR (see Cannon's code) you'd be leaking memory.

I suppose you could save speed with the "own" option (you won't need to CLEAR any more)

but the difference is probably negligible.

2019/06/23 9:28、JOHN BAUGHMAN via 4D_Tech <[hidden email]<mailto:[hidden email]>>のメール:
$MyPicture:=SVG_Export_to_picture ($SVGRef)  //The image is correctly rotated but is now in a square picture



**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Rotate Picture

4D Tech mailing list
Not that it is good form to rely on this, but does a SVG document referenced in a local variable get cleared when the method in which it was created terminates?

Thanks,
Keith - CDI

> On Jun 22, 2019, at 9:01 PM, Keisuke Miyako via 4D_Tech <[hidden email]> wrote:
>
> I think the default export option is "copy"
>
> if you don't SVG_CLEAR (see Cannon's code) you'd be leaking memory.
>

**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************
Reply | Threaded
Open this post in threaded view
|

Re: Rotate Picture

4D Tech mailing list
I think not.

a DOM reference is independent from the 4D picture,
except for ones that are embedded (exported with the "Own" option).

then, a 4D text (the local variable) that contains the hex. representation of the reference
is not in any way associated with the DOM reference, or the picture for that matter,
unlike collection or object, so it does not matter that the scope of the variable is local.

it is absolutely your responsibility to keep track of these (old) kinds of references.

2019/06/24 2:04、Keith Culotta via 4D_Tech <[hidden email]<mailto:[hidden email]>>のメール:

Not that it is good form to rely on this, but does a SVG document referenced in a local variable get cleared when the method in which it was created terminates?



**********************************************************************
4D Internet Users Group (4D iNUG)
Archive:  http://lists.4d.com/archives.html
Options: https://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[hidden email]
**********************************************************************