andy's php projects
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
Script and site usage:
All of the scripts on this site are provided free for non-commerical, personal or non-profit use. If you find these scripts useful to you, appreciate the free support, or are just an all round nice person, then why not donate a little dosh? If you wish to use any of these in a commercial system, please refer to the payment plan.


pass x/y (top/left) value to crop canvas

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    php.amnuts.com Forum Index -> Crop Canvas
View previous topic :: View next topic  
Author Message
mmjaeger
Light Poster


Joined: 22 Oct 2004
Posts: 25

PostPosted: Sat Feb 05, 2005 12:48 pm    Post subject: pass x/y (top/left) value to crop canvas Reply with quote

Hello

Is it possible to pass not only width and height of the cropping area but also the x/y coordinates to the crop canvas script.

how could this be done?

thanks in advance for the help.
Back to top
View user's profile Send private message
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Mon Feb 07, 2005 4:14 am    Post subject: Reply with quote

Hi,

You mean so that you can start the cropping area off in a specific place, not just the top left corner?

Okay, start by adding a couple variables to the class and a method to take the parameters. For example:

PHP:
<?php

// ...

var $startPosX 0;
var 
$startPosY 0;

// ...

function setCropStartPosition($x$y)
{
    
$this->startPosX $x;
    
$this->startPosY $y;
}

// ...

?>


Then you want to update this line:

Code:
dd.elements.theCrop.defx = dd.elements.theImage.x;


so that you check for the start positions. If they are set, then alter the default x/y, else just have it as above. As it's within the hereto statement, you'll have to break that to put in your if condition. Such as:

PHP:
<?php

// ...

        
echo <<< EOT
<script type="text/javascript">
<!--

    SET_DHTML(
$params);

    dd.elements.theCrop.moveTo(dd.elements.theImage.x, dd.elements.theImage.y);
    dd.elements.theCrop.setZ(dd.elements.theImage.z+1);
    dd.elements.theImage.addChild("theCrop");
EOT;

        if (
$this->startPosX) {
            echo 
'dd.elements.theCrop.defx = dd.elements.theImage.x + ' $this->startPosX ";\n";
            echo 
'dd.elements.theCrop.defy = dd.elements.theImage.y + ' $this->startPosY ";\n";
        } else {
            echo 
"dd.elements.theCrop.defx = dd.elements.theImage.x;\n";
        }

        echo <<< EOT

// ...

?>


Well, something like that anyway.... The above is off the top of my head first thing on a monday morning, so expect to tweak it a little. Wink

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
mmjaeger
Light Poster


Joined: 22 Oct 2004
Posts: 25

PostPosted: Tue Feb 08, 2005 3:26 am    Post subject: x/y start position Reply with quote

Hello Andy,

thank again for your help.

I finally got it working - actually real easy - besides passing the x/y values I just had to move theCrop by those values:

Code:
SET_DHTML($params);
    dd.elements.theCrop.moveTo(dd.elements.theImage.x, dd.elements.theImage.y);
    dd.elements.theCrop.setZ(dd.elements.theImage.z+1);
    dd.elements.theImage.addChild("theCrop");
    dd.elements.theCrop.defx = dd.elements.theImage.x;
   
   // if x/y are set, move to position   
   if ($this->startPosX) {
      dd.elements.theCrop.moveTo($this->startPosX,$this->startPosY);
   }


thanks again for your help.
Back to top
View user's profile Send private message
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Tue Feb 08, 2005 4:51 am    Post subject: Reply with quote

ah! The moveTo() method in the javascript! Brilliant! Smile I wish I had thought of that. Smile

This is how my loadJavascript method now looks:

Code:


    // ... the start of the function, and then...

                echo <<< EOT
<script type="text/javascript">
<!--

        SET_DHTML($params);

EOT;
            echo 'dd.elements.theCrop.moveTo(dd.elements.theImage.x + ' . $this->startPosX . ', dd.elements.theImage.y + ' . $this->startPosY . ");\n";
                echo <<< EOT
        dd.elements.theCrop.setZ(dd.elements.theImage.z+1);
        dd.elements.theImage.addChild("theCrop");
        dd.elements.theCrop.defx = dd.elements.theImage.x;
        dd.elements.theCrop.defy = dd.elements.theImage.y;

        // ... and so on



As can be seen at:

http://php.amnuts.com/demos/crop-canvas/interactive3/

One day I'll get around to releasing a new version with all this extra functionality built in!

Cheers,

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Tue Feb 08, 2005 5:11 am    Post subject: Reply with quote

Actually; the moveBy method might be better to use, but oh well... Both work great!
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
mmjaeger
Light Poster


Joined: 22 Oct 2004
Posts: 25

PostPosted: Tue Feb 08, 2005 5:19 am    Post subject: Reply with quote

amnuts wrote:
Actually; the moveBy method might be better to use, but oh well... Both work great!


why do you put the whole stuff between the EOT? I had to take it out in order to make it work?
Back to top
View user's profile Send private message
amnuts
Site Admin


Joined: 01 Sep 2002
Posts: 662
Location: East Sussex, England

PostPosted: Tue Feb 08, 2005 5:45 am    Post subject: Reply with quote

mmjaeger wrote:
why do you put the whole stuff between the EOT? I had to take it out in order to make it work?


I'm using the 'heredoc' method of outputting a lot of text.

http://www.php.net/manual/en/language.types.string.php
http://www.totalchoicehosting.com/forums/lofiversion/index.php/t13729.html

I could, I suppose, actually embed the variables in the heredoc output rather than breaking it up. But, oh well, it was only a demo.

Andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    php.amnuts.com Forum Index -> Crop Canvas All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group