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.


Square Cropping

 
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
gomer
Newbie


Joined: 28 Jan 2005
Posts: 2

PostPosted: Fri Jan 28, 2005 10:12 pm    Post subject: Square Cropping Reply with quote

Hi thanks for the wonderful classes just a quick question is there a way to force the cropping area using the intereface to be the same width and height such that all the images will be square even though they are different sizes for example 200x200 350x350 etc. ?
Back to top
View user's profile Send private message
amnuts
Site Admin


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

PostPosted: Sun Jan 30, 2005 3:53 am    Post subject: Reply with quote

Hi, and welcome to the board!

For that you just need to set the w/h of the cropping area before you load the interface. You can do this with the following method:

PHP:
<?php /**
    * @return void
    * @param int $w
    * @param int $h
    * @desc Sets the initial size of the cropping area.
    * If this is not specifically set, then the cropping size will be a fifth of the image size.
    */
    
function setCropDefaultSize($w$h?>


and coupled with that you might also want to set the minimum size of the cropping area:

PHP:
<?php /**
    * @return void
    * @param int $w
    * @param int $h
    * @desc Sets the minimum size the crop area can be
    */
    
function setCropMinSize($w 25$h 25?>


So you'd end up with something looking like:

PHP:
<?php <?php

    
require_once('class.cropinterface.php');
    
$ci =& new cropInterface();
    
    if (
$_GET['file'])
    {
        
$ci->loadImage($_GET['file']);
        
$ci->cropToDimensions($_GET['sx'], $_GET['sy'], $_GET['ex'], $_GET['ey']);
        
header('Content-type: image/jpeg');
        
$ci->showImage('jpg'100);
        exit;
    }

?>

<html>
<body>

<?php

    $ci
->setCropDefaultSize(200200);
    
$ci->loadInterface('mypicture.jpg');
    
$ci->loadJavaScript();

?>

</body>
</html> ?>



I've done a similar thing automatically and through the cropping interface. Basically I determine the size of the image, take the smallest dimension of that and then use that size as my cropping width and height. If doing it automatically through the cropping class then I centre the crop (as usually the subject of the image is in centre frame), else I just pass the width/height to the interface and use the method shown above.


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


Joined: 28 Jan 2005
Posts: 2

PostPosted: Tue Feb 15, 2005 9:54 pm    Post subject: Reply with quote

I dont think I was as clear as I really should have been what im dealing with are very amatuer photos and the main target of the image could be anywhere and the size/shape of the image could be anything so what id like to really be able to do is start with a selection area of say 300 x 300 for example that would only allow you to select in square areas but in variable dimensions. I hope this makes sense I just want all the finished photos to be of the same width and height after i resize them after they are cropped.
Back to top
View user's profile Send private message
amnuts
Site Admin


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

PostPosted: Wed Feb 16, 2005 4:08 am    Post subject: Reply with quote

Hi gomer,

From what I understand, using the code I posted up would work for the most part for you. What you also probably need to do is turn off the resizing option (which just hides the radio button selection) and then make a tweak to the javascript to set the resizing to be proportional rather than any size. This will ensure that you keep the cropping area square, but still allow people to resize the selection area.

So you code looks like this:

PHP:
<?php <?php

    
require_once('class.cropinterface.php');
    
$ci =& new cropInterface();
    
    if (
$_GET['file'])
    {
        
$ci->loadImage($_GET['file']);
        
$ci->cropToDimensions($_GET['sx'], $_GET['sy'], $_GET['ex'], $_GET['ey']);
        
header('Content-type: image/jpeg');
        
$ci->showImage('jpg'100);
        exit;
    }

?>

<html>
<body>

<?php

    $ci
->setCropDefaultSize(300300);
    
$ci->setResizing(false);
    
$ci->loadInterface('mypicture.jpg');
    
$ci->loadJavaScript();

?>

</body>
</html> ?>


And in the class.cropinterface.php file you'll need to add these two lines:

Code:
    dd.elements.theCrop.scalable  = 1;
    dd.elements.theCrop.resizable = 0;


which are in the loadJavascript method. So it'll end up having:

Code:
<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");
    dd.elements.theCrop.defx = dd.elements.theImage.x;
    dd.elements.theCrop.scalable  = 1;
    dd.elements.theCrop.resizable = 0;


Try it out and see if it gives the functionality you want.

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


Joined: 12 Oct 2004
Posts: 10
Location: Atlanta, GA

PostPosted: Fri Feb 18, 2005 6:23 am    Post subject: Reply with quote

Hi Andy,
Greetings from Atlanta.
You said in an above post:

Quote:
I've done a similar thing automatically and through the cropping interface. Basically I determine the size of the image, take the smallest dimension of that and then use that size as my cropping width and height. If doing it automatically through the cropping class then I centre the crop (as usually the subject of the image is in centre frame), else I just pass the width/height to the interface and use the method shown above.


I tried this with my photo album and found that it is not dependable. That is, it misses a thumbnail sometimes. Sometimes it displays the same one twice or does not display one at all. This seems to be rather random. If I refresh multiple times, it does this differently each time. It seems like I am trying to read the cropped file to make the shadowed pic before the cropped file is totally written. I am doing it just the way you said in the above quote.
I looked at the functions and cropToSize puts the result in _imgFinal and the dropshadow function, resizeToSize takes it from _imgOrig. Would it be possible to combine the two somehow so that you won't have to write the file and then read it right back? I haven't tried anything yet but wanted your input first.
If you have time, you can see the intermittent results by going to this link and viewing the various folders. Try refreshing a few times to see what I mean. Try the OurHome folder or one of the others with numerous pics.
http://www.gaclarke.com/gallery/indexc.php
Thanks again for your help.
George
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
olfudydudy
Newbie


Joined: 12 Oct 2004
Posts: 10
Location: Atlanta, GA

PostPosted: Fri Feb 18, 2005 8:24 am    Post subject: Reply with quote

Hi Andy,
Greeting from Atlanta.
Just wanted to let you know that I solved my problem with the previous post. Basically, instead of loading the cropped file, I inserted this statement:
Code:
$crop->_imgFinal = $drop->_imgOrig;

This workd great. My final test script to do this is the following:
Code:
<?php
       require 'class.dropshadow.php';
       require '../crop/class.cropcanvas.php';
      $image="aspiderweb.jpg";
      $inf=getimagesize($image);
      $w=$inf[0];
      $h=$inf[1];
      ($w>$h) ? $w=$h : $h=$w;
      $cc = new canvasCrop();
      if ($cc->loadImage(dirname(__FILE__). '/'.$image))
      {
   $cc->cropToSize($w, $h, ccCENTER);
        $w=100;
        $h=0;
   $ds = new dropShadow(FALSE);
   $ds->setShadowPath(dirname(__FILE__)."\\");
        $ds->_imgOrig = $cc->_imgFinal;
   $ds->resizeToSize($w,$h);
   $ds->applyShadow();
        $ds->showShadow('png');
     }

?>

In use, I pass it filename, etc and call it from an <img> tag.
Well, gotta get back to work before the boss comes looking for me.
George
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
amnuts
Site Admin


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

PostPosted: Fri Feb 18, 2005 8:32 am    Post subject: Reply with quote

You're too fast, George! Don't even give me a chance to respond.. Sheesh! Wink Good job on working it out!

andy
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
olfudydudy
Newbie


Joined: 12 Oct 2004
Posts: 10
Location: Atlanta, GA

PostPosted: Fri Feb 18, 2005 11:12 am    Post subject: Reply with quote

Hi Andy,
Sorry about that but I was so excited to get it working, I had to tell somebody. Also, I didn't want you to go look at it, expecting to find something wrong with it and find it working perfectly.
The next thing I want to do with it is to add your overlay, which I have working in another area, but incorporate it with this photo gallery. I will try to do this today. It's just too bad I can't chage the color of the little white corners. So far I have no graphic editor to do that and not mess up the transparent area. Oh well. I'll get there eventually.
Have a great day.
George
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address
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